Bug 1370871 - Remove use of global from Firefox refresh test; r=Gijs
authorAndreas Tolfsen <ato@mozilla.com>
Thu, 08 Jun 2017 13:46:12 +0100
changeset 413700 ba02f6a155b8d2d44882686d669cd15033cdef5a
parent 413699 c9a85535d60760870ed3d586e129a4a3a4f9340e
child 413701 9933f2d4d1885c5b730fb5d5a5103d77219be57d
push id1490
push usermtabara@mozilla.com
push dateMon, 31 Jul 2017 14:08:16 +0000
treeherdermozilla-release@70e32e6bf15e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1370871
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1370871 - Remove use of global from Firefox refresh test; r=Gijs The previous commit removes the "global" global exposed n Marionette script evaluation environments. This patch makes use of named sandboxes that are maintained for the lifetime of the test. MozReview-Commit-ID: D2YjOQxULtk
browser/components/migration/tests/marionette/test_refresh_firefox.py
--- a/browser/components/migration/tests/marionette/test_refresh_firefox.py
+++ b/browser/components/migration/tests/marionette/test_refresh_firefox.py
@@ -2,16 +2,18 @@ import os
 import shutil
 import time
 
 from marionette_harness import MarionetteTestCase
 from marionette_driver.errors import NoAlertPresentException
 
 
 class TestFirefoxRefresh(MarionetteTestCase):
+    _sandbox = "firefox-refresh"
+
     _username = "marionette-test-login"
     _password = "marionette-test-password"
     _bookmarkURL = "about:mozilla"
     _bookmarkText = "Some bookmark from Marionette"
 
     _cookieHost = "firefox-refresh.marionette-test.mozilla.org"
     _cookiePath = "some/cookie/path"
     _cookieName = "somecookie"
@@ -32,25 +34,25 @@ class TestFirefoxRefresh(MarionetteTestC
             "http://test.marionette.mozilla.com/some/form/",
             null,
             arguments[0],
             arguments[1],
             "username",
             "password"
           );
           Services.logins.addLogin(myLogin)
-        """, script_args=[self._username, self._password])
+        """, script_args=(self._username, self._password))
 
     def createBookmark(self):
         self.marionette.execute_script("""
           let url = arguments[0];
           let title = arguments[1];
           PlacesUtils.bookmarks.insertBookmark(PlacesUtils.bookmarks.bookmarksMenuFolder,
             makeURI(url), 0, title);
-        """, script_args=[self._bookmarkURL, self._bookmarkText])
+        """, script_args=(self._bookmarkURL, self._bookmarkText))
 
     def createHistory(self):
         error = self.runAsyncCode("""
           // Copied from PlacesTestUtils, which isn't available in Marionette tests.
           let didReturn;
           PlacesUtils.asyncHistory.updatePlaces(
             [{title: arguments[1], uri: makeURI(arguments[0]), visits: [{
                 transitionType: Ci.nsINavHistoryService.TRANSITION_LINK,
@@ -66,17 +68,17 @@ class TestFirefoxRefresh(MarionetteTestC
               handleResult() {},
               handleCompletion() {
                 if (!didReturn) {
                   marionetteScriptFinished(false);
                 }
               },
             }
           );
-        """, script_args=[self._historyURL, self._historyTitle])
+        """, script_args=(self._historyURL, self._historyTitle))
         if error:
             print error
 
     def createFormHistory(self):
         error = self.runAsyncCode("""
           let updateDefinition = {
             op: "add",
             fieldname: arguments[0],
@@ -90,27 +92,27 @@ class TestFirefoxRefresh(MarionetteTestC
               marionetteScriptFinished(error);
             },
             handleCompletion() {
               if (!finished) {
                 marionetteScriptFinished(false);
               }
             }
           });
-        """, script_args=[self._formHistoryFieldName, self._formHistoryValue])
+        """, script_args=(self._formHistoryFieldName, self._formHistoryValue))
         if error:
           print error
 
     def createCookie(self):
         self.runCode("""
           // Expire in 15 minutes:
           let expireTime = Math.floor(Date.now() / 1000) + 15 * 60;
           Services.cookies.add(arguments[0], arguments[1], arguments[2], arguments[3],
                                true, false, false, expireTime);
-        """, script_args=[self._cookieHost, self._cookiePath, self._cookieName, self._cookieValue])
+        """, script_args=(self._cookieHost, self._cookiePath, self._cookieName, self._cookieValue))
 
     def createSession(self):
         self.runAsyncCode("""
           const COMPLETE_STATE = Ci.nsIWebProgressListener.STATE_STOP +
                                  Ci.nsIWebProgressListener.STATE_IS_NETWORK;
           let {TabStateFlusher} = Cu.import("resource:///modules/sessionstore/TabStateFlusher.jsm", {});
           let expectedURLs = Array.from(arguments[0])
           gBrowser.addTabsProgressListener({
@@ -137,17 +139,17 @@ class TestFirefoxRefresh(MarionetteTestC
           }
           // Close any other tabs that might be open:
           let allTabs = Array.from(gBrowser.tabs);
           for (let tab of allTabs) {
             if (!expectedTabs.has(tab)) {
               gBrowser.removeTab(tab);
             }
           }
-        """, script_args=[self._expectedURLs])
+        """, script_args=(self._expectedURLs,))
 
     def checkPassword(self):
         loginInfo = self.marionette.execute_script("""
           let ary = Services.logins.findLogins({},
             "test.marionette.mozilla.com",
             "http://test.marionette.mozilla.com/some/form/",
             null, {});
           return ary.length ? ary : {username: "null", password: "null"};
@@ -161,31 +163,31 @@ class TestFirefoxRefresh(MarionetteTestC
         """)
         self.assertEqual(loginCount, 1, "No other logins are present")
 
     def checkBookmark(self):
         titleInBookmarks = self.marionette.execute_script("""
           let url = arguments[0];
           let bookmarkIds = PlacesUtils.bookmarks.getBookmarkIdsForURI(makeURI(url), {}, {});
           return bookmarkIds.length == 1 ? PlacesUtils.bookmarks.getItemTitle(bookmarkIds[0]) : "";
-        """, script_args=[self._bookmarkURL])
+        """, script_args=(self._bookmarkURL,))
         self.assertEqual(titleInBookmarks, self._bookmarkText)
 
     def checkHistory(self):
         historyResult = self.runAsyncCode("""
           PlacesUtils.history.fetch(arguments[0]).then(pageInfo => {
             if (!pageInfo) {
               marionetteScriptFinished("No visits found");
             } else {
               marionetteScriptFinished(pageInfo);
             }
           }).catch(e => {
             marionetteScriptFinished("Unexpected error in fetching page: " + e);
           });
-        """, script_args=[self._historyURL])
+        """, script_args=(self._historyURL,))
         if type(historyResult) == str:
             self.fail(historyResult)
             return
 
         self.assertEqual(historyResult['title'], self._historyTitle)
 
     def checkFormHistory(self):
         formFieldResults = self.runAsyncCode("""
@@ -196,17 +198,17 @@ class TestFirefoxRefresh(MarionetteTestC
             },
             handleResult(result) {
               results.push(result);
             },
             handleCompletion() {
               marionetteScriptFinished(results);
             },
           });
-        """, script_args=[self._formHistoryFieldName])
+        """, script_args=(self._formHistoryFieldName,))
         if type(formFieldResults) == str:
             self.fail(formFieldResults)
             return
 
         formFieldResultCount = len(formFieldResults)
         self.assertEqual(formFieldResultCount, 1, "Should have exactly 1 entry for this field, got %d" % formFieldResultCount)
         if formFieldResultCount == 1:
             self.assertEqual(formFieldResults[0]['value'], self._formHistoryValue)
@@ -238,17 +240,17 @@ class TestFirefoxRefresh(MarionetteTestC
                 return "more than 1 cookie! That shouldn't happen!";
               }
               cookie = hostCookie;
             }
             return {path: cookie.path, name: cookie.name, value: cookie.value};
           } catch (ex) {
             return "got exception trying to fetch cookie: " + ex;
           }
-        """, script_args=[self._cookieHost])
+        """, script_args=(self._cookieHost,))
         if not isinstance(cookieInfo, dict):
             self.fail(cookieInfo)
             return
         self.assertEqual(cookieInfo['path'], self._cookiePath)
         self.assertEqual(cookieInfo['value'], self._cookieValue)
         self.assertEqual(cookieInfo['name'], self._cookieName)
 
     def checkSession(self):
@@ -304,28 +306,37 @@ class TestFirefoxRefresh(MarionetteTestC
         self.createBookmark()
         self.createHistory()
         self.createFormHistory()
         self.createCookie()
         self.createSession()
 
     def setUpScriptData(self):
         self.marionette.set_context(self.marionette.CONTEXT_CHROME)
-        self.marionette.execute_script("""
+        self.runCode("""
+          window.global = {};
           global.LoginInfo = Components.Constructor("@mozilla.org/login-manager/loginInfo;1", "nsILoginInfo", "init");
           global.profSvc = Cc["@mozilla.org/toolkit/profile-service;1"].getService(Ci.nsIToolkitProfileService);
           global.Preferences = Cu.import("resource://gre/modules/Preferences.jsm", {}).Preferences;
           global.FormHistory = Cu.import("resource://gre/modules/FormHistory.jsm", {}).FormHistory;
-        """, new_sandbox=False, sandbox='system')
+        """)
 
     def runCode(self, script, *args, **kwargs):
-        return self.marionette.execute_script(script, new_sandbox=False, sandbox='system', *args, **kwargs)
+        return self.marionette.execute_script(script,
+                                              new_sandbox=False,
+                                              sandbox=self._sandbox,
+                                              *args,
+                                              **kwargs)
 
     def runAsyncCode(self, script, *args, **kwargs):
-        return self.marionette.execute_async_script(script, new_sandbox=False, sandbox='system', *args, **kwargs)
+        return self.marionette.execute_async_script(script,
+                                                    new_sandbox=False,
+                                                    sandbox=self._sandbox,
+                                                    *args,
+                                                    **kwargs)
 
     def setUp(self):
         MarionetteTestCase.setUp(self)
         self.setUpScriptData()
 
         self.reset_profile_path = None
         self.desktop_backup_path = None
 
@@ -356,17 +367,17 @@ class TestFirefoxRefresh(MarionetteTestC
 
         if self.reset_profile_path:
             # Remove ourselves from profiles.ini
             self.runCode("""
               let name = arguments[0];
               let profile = global.profSvc.getProfileByName(name);
               profile.remove(false)
               global.profSvc.flush();
-            """, script_args=[self.profileNameToRemove])
+            """, script_args=(self.profileNameToRemove,))
             # And delete all the files.
             shutil.rmtree(self.reset_profile_path, ignore_errors=False, onerror=handleRemoveReadonly)
 
     def doReset(self):
         profileName = "marionette-test-profile-" + str(int(time.time() * 1000))
         self.profileNameToRemove = profileName
         self.runCode("""
           // Ensure the current (temporary) profile is in profiles.ini:
@@ -382,17 +393,17 @@ class TestFirefoxRefresh(MarionetteTestC
           let prefObj = {};
           for (let pref of prefsToKeep) {
             prefObj[pref] = global.Preferences.get(pref);
           }
           env.set("MOZ_MARIONETTE_PREF_STATE_ACROSS_RESTARTS", JSON.stringify(prefObj));
           env.set("MOZ_RESET_PROFILE_RESTART", "1");
           env.set("XRE_PROFILE_PATH", arguments[0]);
           env.set("XRE_PROFILE_NAME", profileName);
-        """, script_args=[self.marionette.instance.profile.profile, profileName])
+        """, script_args=(self.marionette.instance.profile.profile, profileName,))
 
         profileLeafName = os.path.basename(os.path.normpath(self.marionette.instance.profile.profile))
 
         # Now restart the browser to get it reset:
         self.marionette.restart(clean=False, in_app=True)
         self.setUpScriptData()
 
         # Determine the new profile path (we'll need to remove it when we're done)
@@ -409,17 +420,17 @@ class TestFirefoxRefresh(MarionetteTestC
           } catch (ex) {
             container = Services.dirsvc.get("Home", Ci.nsIFile);
           }
           let bundle = Services.strings.createBundle("chrome://mozapps/locale/profile/profileSelection.properties");
           let dirName = bundle.formatStringFromName("resetBackupDirectory", [Services.appinfo.name], 1);
           container.append(dirName);
           container.append(arguments[0]);
           return container.path;
-        """, script_args = [profileLeafName])
+        """, script_args=(profileLeafName,))
 
         self.assertTrue(os.path.isdir(self.reset_profile_path), "Reset profile path should be present")
         self.assertTrue(os.path.isdir(self.desktop_backup_path), "Backup profile path should be present")
         self.assertTrue(self.profileNameToRemove in self.reset_profile_path, "Reset profile path should contain profile name to remove")
 
     def testReset(self):
         self.checkProfile()