Bug 848420 - (Part 2) Test for distribution search engines. r=gbrown
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Mon, 18 Mar 2013 15:39:08 -0700
changeset 131747 7dafe64aa7f71198ceb5fe5c143b8709fdbd82a1
parent 131746 f49cd7c9b7664296c92d05098d8287a7cfda2240
child 131748 260c1b2a4b3390f015f97d59d2f42e512eb127ce
push idunknown
push userunknown
push dateunknown
reviewersgbrown
bugs848420
milestone22.0a1
Bug 848420 - (Part 2) Test for distribution search engines. r=gbrown
mobile/android/base/tests/assets/mock-package.zip
mobile/android/base/tests/testDistribution.java.in
index 408c6b9fc11eb0526a4dfb00fd62689b491c6f6b..c7742ea6dbd599e6c11d9cd8663ac0699e02cafc
GIT binary patch
literal 2272
zc$}40cTm$=7yTsxrAlByqy&jT0EJM5P(*`)HREEWCv*%DNTeht(gos5TcimHA`2{a
zMWlnFh_s-9AV`z46u~TtN|PoiF6zuTj=O$4`)1zEz4woE-rRTQ95WLLmnZ-LJb<zt
z9ixCW^H1jn0Db`gPywU?Hwxn-o#NtqkwW!RV~~h+S2E4Z*Ms82P;;evd+!cOKD!+W
z8Q|?@ZN&>fkak#ebsE;(H-H}iajk&>;4}IV-kULlg6?EFKhtDn`q_cu%pNhioU4&E
zro7F5I-`PQyL{xX7er@cs^P&Nq`&u~`<A99qSDE4?e#)l9DYLRSTDyyx?O82_<F{x
zpoq5n!Z!vL8@n!{Zt-0g@+V9v56iXTC&JCLuc(IpQ9KeGvFKT&@~E_N+R%~EwC|9G
z=isY1V+g*=1K66)+A@46{I#r$X?@h9yRN$f9OTN3Zm7Asdi%(;k!W&9bHOooMOk%S
zHYz9<hg_;7LZRYmGuaI_y(}kRG4z=m4v`H1*h2f@2A-d?&Z?)GCyyE$Hnfi35Xpc&
z^e=q8x}o*-R>X;Ss;qIJofxQyaMCq_se1<xX&6diAmD+}os)Ju=6$Dkj-!<qZk-t+
z7FOmTjV@{V!DLdKJqn-D`Yr6~fz4XVKAG|xLmDU5S$&X7s0a-avq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ag|*+0LKf;=QufUquctIk%Cw5YZ%oY~LAI7=IHIp8IZ6P++1xJKl4A@*&tY
zQci8hs;F@}`x&fww42eyIq#H!ep|*22X|j^v`)B~@HVGw{qQ(n+Pn`quk21}&go@a
zZQ_0dp8I&-`z5)~0+kl;jcU412SY8d@H4D`(}<}%zorD+8`ZlZE|1rhTf%k4mx=vg
zA2fqe?LEldY@9OvBQYnx{x(6^#D7*T)#R<SWV!Fu!v!gRqDaI^fe{W+4MwARg|<8O
zvO1za?#sWjVGB+7(B<!9FE4r0w!*HpC8CFtex8?DLwCf5eK@yrPgkl_sY);N2%Nu3
z_k8AyS#tL~kO9=l%j{}v@ser(TtobfH0vO9_G6ira@LD0vMUQao7K;*g_zgr_r&OY
zm>3#bG~2a*KH$?~Q*apLeliWRTYtJz-`c+mmFnqDq<b=u=NVL=&u%XZmNs`I{mt#|
z9r?`u7c1l<2aJ59`r|)$I}{iIVBg}>=p=U%o#f+6`U?4?uKGVA$0cfbLNo*-Hnznc
zB&yEI8KrsUq#y}FiTmrvJQRd=@rfZY$(5-iiqZsfzkBlgtko0mY?KSKA$n4)7O;Y3
znZ`kVqpr0UdVF(GsQH~dxcD;8c*s#$Fn^1aXM>j#ARkv2x;+c}6&9D>%&QzjfeZZ}
zXf3NBDX7kt={KIyAf3{2tH=Pm{dABeH&wgL>J{cLSCBJV$4Nb)KW+<uVnKz3+KNw~
z&84L?H7#oW^bV%t7{k%5o;x8S4mGA#MYXsO3<7S&G<IjPU<-W_QW5Gr72I6Y7rHmG
zd9@lHW&QiSl$i+#ECcyoDj)d#UAr3r@-Kg?{#!<Kf63@?_WFhKdqVh{@gq0z|7F4b
nMHc@^@I6I*O+eTK{F^?wzv$y{6x@4&&u@kRsNG@8-cQ|Mg&@ZF
--- a/mobile/android/base/tests/testDistribution.java.in
+++ b/mobile/android/base/tests/testDistribution.java.in
@@ -18,16 +18,19 @@ import org.json.JSONObject;
 
 /**
  * Tests distribution customization.
  * mock-package.zip should contain the following directory structure:
  *
  *   distribution/
  *     preferences.json
  *     bookmarks.json
+ *     searchplugins/
+ *       common/
+ *         engine.xml
  */
 public class testDistribution extends ContentProviderTest {
     private static final String MOCK_PACKAGE = "mock-package.zip";
     private static final String PREF_REQUEST_ID = "testDistribution";
 
     private Activity mActivity;
 
     @Override
@@ -41,16 +44,17 @@ public class testDistribution extends Co
         String mockPackagePath = getMockPackagePath();
 
         // Pre-clear distribution pref, run basic preferences and en-US localized preferences Tests
         clearDistributionPref();
         setTestLocale("en-US");
         initDistribution(mockPackagePath);
         checkPreferences();
         checkLocalizedPreferences("en-US");
+        checkSearchPlugin();
 
         // Pre-clear distribution pref, and run es-MX localized preferences Test
         clearDistributionPref();
         setTestLocale("es-MX");
         initDistribution(mockPackagePath);
         checkLocalizedPreferences("es-MX");
     }
 
@@ -125,16 +129,38 @@ public class testDistribution extends Co
                 }
             }
 
         } catch (JSONException e) {
             mAsserter.ok(false, "exception getting preferences", e.toString());
         }
     }
 
+    private void checkSearchPlugin() {
+        Actions.RepeatedEventExpecter eventExpecter = mActions.expectGeckoEvent("SearchEngines:Data");
+        mActions.sendGeckoEvent("SearchEngines:Get", null);
+
+        try {
+            JSONObject data = new JSONObject(eventExpecter.blockForEventData());
+            JSONArray searchEngines = data.getJSONArray("searchEngines");
+            boolean foundEngine = false;
+            for (int i = 0; i < searchEngines.length(); i++) {
+                JSONObject engine = (JSONObject) searchEngines.get(i);
+                String name = engine.getString("name");
+                if (name.equals("Test search engine")) {
+                    foundEngine = true;
+                    break;
+                }
+            }
+            mAsserter.ok(foundEngine, "check search plugin", "found test search plugin");
+        } catch (JSONException e) {
+            mAsserter.ok(false, "exception getting search plugins", e.toString());
+        }
+    }
+
     // Sets the distribution locale preference for the test
     private void setTestLocale(String aLocale) {
         String prefUseragentLocale = "general.useragent.locale";
 
         JSONObject jsonPref = new JSONObject();
         try {
             // Request the pref change to the locale.
             jsonPref.put("name", prefUseragentLocale);
@@ -260,29 +286,35 @@ public class testDistribution extends Co
     }
 
     @Override
     public void setUp() throws Exception {
         // TODO: Set up the content provider after setting the distribution.
         super.setUp("@ANDROID_PACKAGE_NAME@.db.BrowserProvider", "AUTHORITY");
     }
 
+    private void delete(File file) throws Exception {
+      if (file.isDirectory()) {
+        File[] files = file.listFiles();
+        for (File f : files) {
+          delete(f);
+        }
+      }
+      mAsserter.ok(file.delete(), "clean up distribution files", "deleted " + file.getPath());
+    }
+
     @Override
     public void tearDown() throws Exception {
         File dataDir = new File(mActivity.getApplicationInfo().dataDir);
 
         // Delete mock package from data directory.
         File mockPackage = new File(dataDir, MOCK_PACKAGE);
         mAsserter.ok(mockPackage.delete(), "clean up mock package", "deleted " + mockPackage.getPath());
 
-        // Delete distribution files that Distribution.init copied to data directory.
+        // Recursively delete distribution files that Distribution.init copied to data directory.
         File distDir = new File(dataDir, "distribution");
-        File[] files = distDir.listFiles();
-        for (File f : files) {
-            mAsserter.ok(f.delete(), "clean up distribution files", "deleted " + f.getPath());
-        }
-        mAsserter.ok(distDir.delete(), "clean up distribution directory", "deleted distribution directory");
+        delete(distDir);
 
         clearDistributionPref();
 
         super.tearDown();
     }
 }