diff options
author | samuong <samuong@chromium.org> | 2015-08-24 16:54:10 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-08-24 23:54:55 +0000 |
commit | cdb9045ff3179034d3ad67117c8a18bdfaad58cb (patch) | |
tree | 2acae6c1792578b125f7f6e8d9ed54387a657a3d | |
parent | 39e165f9a18b4648c309ef4ca33f92817bd34fb9 (diff) | |
download | chromium_src-cdb9045ff3179034d3ad67117c8a18bdfaad58cb.zip chromium_src-cdb9045ff3179034d3ad67117c8a18bdfaad58cb.tar.gz chromium_src-cdb9045ff3179034d3ad67117c8a18bdfaad58cb.tar.bz2 |
[chromedriver] Call Runtime.evaluate when checking for pending navigations.
This forces a roundtrip to the renderer process, and is needed to flush out any pending navigations that originated in the renderer.
BUG=524079,chromedriver:1202
Review URL: https://codereview.chromium.org/1311253004
Cr-Commit-Position: refs/heads/master@{#345212}
-rw-r--r-- | chrome/test/chromedriver/chrome/navigation_tracker.cc | 18 | ||||
-rw-r--r-- | chrome/test/chromedriver/chrome/navigation_tracker_unittest.cc | 8 | ||||
-rwxr-xr-x | chrome/test/chromedriver/test/run_py_tests.py | 42 |
3 files changed, 59 insertions, 9 deletions
diff --git a/chrome/test/chromedriver/chrome/navigation_tracker.cc b/chrome/test/chromedriver/chrome/navigation_tracker.cc index 9275949..0f31e78 100644 --- a/chrome/test/chromedriver/chrome/navigation_tracker.cc +++ b/chrome/test/chromedriver/chrome/navigation_tracker.cc @@ -45,6 +45,24 @@ NavigationTracker::~NavigationTracker() {} Status NavigationTracker::IsPendingNavigation(const std::string& frame_id, bool* is_pending) { + if (!IsExpectingFrameLoadingEvents()) { + // Some DevTools commands (e.g. Input.dispatchMouseEvent) are handled in the + // browser process, and may cause the renderer process to start a new + // navigation. We need to call Runtime.evaluate to force a roundtrip to the + // renderer process, and make sure that we notice any pending navigations + // (see crbug.com/524079). + base::DictionaryValue params; + params.SetString("expression", "1"); + scoped_ptr<base::DictionaryValue> result; + Status status = client_->SendCommandAndGetResult( + "Runtime.evaluate", params, &result); + int value = 0; + if (status.IsError() || + !result->GetInteger("result.value", &value) || + value != 1) + return Status(kUnknownError, "cannot determine loading status", status); + } + if (loading_state_ == kUnknown) { // In the case that a http request is sent to server to fetch the page // content and the server hasn't responded at all, a dummy page is created diff --git a/chrome/test/chromedriver/chrome/navigation_tracker_unittest.cc b/chrome/test/chromedriver/chrome/navigation_tracker_unittest.cc index 922c6a8..d929b93 100644 --- a/chrome/test/chromedriver/chrome/navigation_tracker_unittest.cc +++ b/chrome/test/chromedriver/chrome/navigation_tracker_unittest.cc @@ -49,6 +49,14 @@ class DeterminingLoadStateDevToolsClient : public StubDevToolsClient { result_dict.SetString("root.baseURL", "http://test"); result->reset(result_dict.DeepCopy()); return Status(kOk); + } else if (method == "Runtime.evaluate") { + std::string expression; + if (params.GetString("expression", &expression) && expression == "1") { + base::DictionaryValue result_dict; + result_dict.SetInteger("result.value", 1); + result->reset(result_dict.DeepCopy()); + return Status(kOk); + } } if (send_event_first_.length()) { diff --git a/chrome/test/chromedriver/test/run_py_tests.py b/chrome/test/chromedriver/test/run_py_tests.py index e01d9e9..e210138 100755 --- a/chrome/test/chromedriver/test/run_py_tests.py +++ b/chrome/test/chromedriver/test/run_py_tests.py @@ -66,6 +66,10 @@ _VERSION_SPECIFIC_FILTER['HEAD'] = [ # https://code.google.com/p/chromedriver/issues/detail?id=992 'ChromeDownloadDirTest.testDownloadDirectoryOverridesExistingPreferences', ] +_VERSION_SPECIFIC_FILTER['44'] = [ + # https://code.google.com/p/chromedriver/issues/detail?id=1202 + 'ChromeDownloadDirTest.testFileDownloadWithGet', +] _VERSION_SPECIFIC_FILTER['37'] = [ # https://code.google.com/p/chromedriver/issues/detail?id=954 'MobileEmulationCapabilityTest.testClickElement', @@ -1151,11 +1155,11 @@ class ChromeDriverTest(ChromeDriverBaseTest): self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html')) self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html#x')) - def setCookie(self, request): + def SetCookie(self, request): return {'Set-Cookie': 'x=y; HttpOnly'}, "<!DOCTYPE html><html></html>" def testGetHttpOnlyCookie(self): - self._http_server.SetCallbackForPath('/setCookie', self.setCookie) + self._http_server.SetCallbackForPath('/setCookie', self.SetCookie) self._driver.Load(self.GetHttpUrlForFile('/setCookie')) self._driver.AddCookie({'name': 'a', 'value': 'b'}) cookies = self._driver.GetCookies() @@ -1215,6 +1219,17 @@ class ChromeDownloadDirTest(ChromeDriverBaseTest): self._temp_dirs.append(temp_dir) return temp_dir + def RespondWithCsvFile(self, request): + return {'Content-Type': 'text/csv'}, 'a,b,c\n1,2,3\n' + + def WaitForFileToDownload(self, path): + deadline = time.time() + 60 + while True: + time.sleep(0.1) + if os.path.isfile(path) or time.time() > deadline: + break + self.assertTrue(os.path.isfile(path), "Failed to download file!") + def tearDown(self): # Call the superclass tearDown() method before deleting temp dirs, so that # Chrome has a chance to exit before its user data dir is blown away from @@ -1223,19 +1238,28 @@ class ChromeDownloadDirTest(ChromeDriverBaseTest): for temp_dir in self._temp_dirs: shutil.rmtree(temp_dir) - def testFileDownload(self): + def testFileDownloadWithClick(self): download_dir = self.CreateTempDir() download_name = os.path.join(download_dir, 'a_red_dot.png') driver = self.CreateDriver(download_dir=download_dir) driver.Load(ChromeDriverTest.GetHttpUrlForFile( '/chromedriver/download.html')) driver.FindElement('id', 'red-dot').Click() - deadline = time.time() + 60 - while True: - time.sleep(0.1) - if os.path.isfile(download_name) or time.time() > deadline: - break - self.assertTrue(os.path.isfile(download_name), "Failed to download file!") + self.WaitForFileToDownload(download_name) + self.assertEqual( + ChromeDriverTest.GetHttpUrlForFile('/chromedriver/download.html'), + driver.GetCurrentUrl()) + + def testFileDownloadWithGet(self): + ChromeDriverTest._http_server.SetCallbackForPath( + '/abc.csv', self.RespondWithCsvFile) + download_dir = self.CreateTempDir() + download_name = os.path.join(download_dir, 'abc.csv') + driver = self.CreateDriver(download_dir=download_dir) + original_url = driver.GetCurrentUrl() + driver.Load(ChromeDriverTest.GetHttpUrlForFile('/abc.csv')) + self.WaitForFileToDownload(os.path.join(download_dir, 'abc.csv')) + self.assertEqual(original_url, driver.GetCurrentUrl()) def testDownloadDirectoryOverridesExistingPreferences(self): user_data_dir = self.CreateTempDir() |