diff options
-rw-r--r-- | chrome/browser/loadtimes_extension_bindings_browsertest.cc | 72 | ||||
-rw-r--r-- | chrome/chrome_tests.gypi | 2 | ||||
-rw-r--r-- | chrome/renderer/loadtimes_extension_bindings_uitest.cc | 75 | ||||
-rw-r--r-- | chrome/test/base/ui_test_utils.cc | 2 |
4 files changed, 74 insertions, 77 deletions
diff --git a/chrome/browser/loadtimes_extension_bindings_browsertest.cc b/chrome/browser/loadtimes_extension_bindings_browsertest.cc new file mode 100644 index 0000000..4e6961a --- /dev/null +++ b/chrome/browser/loadtimes_extension_bindings_browsertest.cc @@ -0,0 +1,72 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/ui/browser.h" +#include "chrome/test/base/in_process_browser_test.h" +#include "chrome/test/base/ui_test_utils.h" +#include "content/public/browser/web_contents.h" +#include "net/test/test_server.h" + +class LoadtimesExtensionBindingsTest : public InProcessBrowserTest { + public: + LoadtimesExtensionBindingsTest() { + EnableDOMAutomation(); + } + + void CompareBeforeAndAfter() { + // TODO(simonjam): There's a race on whether or not first paint is populated + // before we read them. We ought to test that too. Until the race is fixed, + // zero it out so the test is stable. + content::RenderViewHost* rvh = + browser()->GetSelectedWebContents()->GetRenderViewHost(); + ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( + rvh, L"", + L"window.before.firstPaintAfterLoadTime = 0;" + L"window.before.firstPaintTime = 0;" + L"window.after.firstPaintAfterLoadTime = 0;" + L"window.after.firstPaintTime = 0;")); + + std::string before; + std::string after; + ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( + rvh, L"", L"window.domAutomationController.send(" + L"JSON.stringify(before))", &before)); + ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( + rvh, L"", L"window.domAutomationController.send(" + L"JSON.stringify(after))", &after)); + EXPECT_EQ(before, after); + } +}; + +IN_PROC_BROWSER_TEST_F(LoadtimesExtensionBindingsTest, + LoadTimesSameAfterClientInDocNavigation) { + ASSERT_TRUE(test_server()->Start()); + GURL plain_url = test_server()->GetURL("blank"); + ui_test_utils::NavigateToURL(browser(), plain_url); + content::RenderViewHost* rvh = + browser()->GetSelectedWebContents()->GetRenderViewHost(); + ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( + rvh, L"", L"window.before = window.chrome.loadTimes()")); + ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( + rvh, L"", L"window.location.href = window.location + \"#\"")); + ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( + rvh, L"", L"window.after = window.chrome.loadTimes()")); + CompareBeforeAndAfter(); +} + +IN_PROC_BROWSER_TEST_F(LoadtimesExtensionBindingsTest, + LoadTimesSameAfterUserInDocNavigation) { + ASSERT_TRUE(test_server()->Start()); + GURL plain_url = test_server()->GetURL("blank"); + GURL hash_url(plain_url.spec() + "#"); + ui_test_utils::NavigateToURL(browser(), plain_url); + content::RenderViewHost* rvh = + browser()->GetSelectedWebContents()->GetRenderViewHost(); + ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( + rvh, L"", L"window.before = window.chrome.loadTimes()")); + ui_test_utils::NavigateToURL(browser(), hash_url); + ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( + rvh, L"", L"window.after = window.chrome.loadTimes()")); + CompareBeforeAndAfter(); +} diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 3c14a97..e6bffc2 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -776,7 +776,6 @@ 'browser/ui/webui/options2/options_ui2_uitest.cc', 'browser/ui/webui/options2/options_ui2_uitest.h', 'browser/ui/webui/print_preview/print_preview_ui_uitest.cc', - 'renderer/loadtimes_extension_bindings_uitest.cc', 'test/automation/automation_proxy_uitest.cc', 'test/automation/automation_proxy_uitest.h', 'test/automation/extension_proxy_uitest.cc', @@ -2884,6 +2883,7 @@ 'browser/iframe_browsertest.cc', 'browser/infobars/infobar_extension_apitest.cc', 'browser/importer/toolbar_importer_utils_browsertest.cc', + 'browser/loadtimes_extension_bindings_browsertest.cc', 'browser/locale_tests_browsertest.cc', 'browser/logging_chrome_browsertest.cc', 'browser/metrics/metrics_service_browsertest.cc', diff --git a/chrome/renderer/loadtimes_extension_bindings_uitest.cc b/chrome/renderer/loadtimes_extension_bindings_uitest.cc deleted file mode 100644 index 84a7e67..0000000 --- a/chrome/renderer/loadtimes_extension_bindings_uitest.cc +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/test/automation/tab_proxy.h" -#include "chrome/test/ui/ui_test.h" -#include "googleurl/src/gurl.h" -#include "net/test/test_server.h" -#include "testing/gtest/include/gtest/gtest.h" - -class LoadtimesExtensionBindingsUITest : public UITest { - public: - LoadtimesExtensionBindingsUITest() - : http_server_(net::TestServer::TYPE_HTTP, - net::TestServer::kLocalhost, - FilePath()) { - dom_automation_enabled_ = true; - } - - void CompareBeforeAndAfter(TabProxy* tab_proxy) { - // TODO(simonjam): There's a race on whether or not first paint is populated - // before we read them. We ought to test that too. Until the race is fixed, - // zero it out so the test is stable. - ASSERT_TRUE(tab_proxy->ExecuteJavaScript( - "window.before.firstPaintAfterLoadTime = 0;" - "window.before.firstPaintTime = 0;" - "window.after.firstPaintAfterLoadTime = 0;" - "window.after.firstPaintTime = 0;")); - - std::wstring before; - std::wstring after; - ASSERT_TRUE(tab_proxy->ExecuteAndExtractString( - L"", L"window.domAutomationController.send(" - L"JSON.stringify(before))", &before)); - ASSERT_TRUE(tab_proxy->ExecuteAndExtractString( - L"", L"window.domAutomationController.send(" - L"JSON.stringify(after))", &after)); - EXPECT_EQ(before, after); - } - - protected: - net::TestServer http_server_; -}; - -TEST_F(LoadtimesExtensionBindingsUITest, - LoadTimesSameAfterClientInDocNavigation) { - ASSERT_TRUE(http_server_.Start()); - GURL plain_url = http_server_.GetURL("blank"); - NavigateToURL(plain_url); - scoped_refptr<TabProxy> tab_proxy = GetActiveTab(); - ASSERT_TRUE(tab_proxy.get()); - ASSERT_TRUE(tab_proxy->ExecuteJavaScript( - "window.before = window.chrome.loadTimes()")); - ASSERT_TRUE(tab_proxy->ExecuteJavaScript( - "window.location.href = window.location + \"#\"")); - ASSERT_TRUE(tab_proxy->ExecuteJavaScript( - "window.after = window.chrome.loadTimes()")); - CompareBeforeAndAfter(tab_proxy.get()); -} - -TEST_F(LoadtimesExtensionBindingsUITest, - LoadTimesSameAfterUserInDocNavigation) { - ASSERT_TRUE(http_server_.Start()); - GURL plain_url = http_server_.GetURL("blank"); - GURL hash_url(plain_url.spec() + "#"); - NavigateToURL(plain_url); - scoped_refptr<TabProxy> tab_proxy = GetActiveTab(); - ASSERT_TRUE(tab_proxy.get()); - ASSERT_TRUE(tab_proxy->ExecuteJavaScript( - "window.before = window.chrome.loadTimes()")); - NavigateToURL(hash_url); - ASSERT_TRUE(tab_proxy->ExecuteJavaScript( - "window.after = window.chrome.loadTimes()")); - CompareBeforeAndAfter(tab_proxy.get()); -} diff --git a/chrome/test/base/ui_test_utils.cc b/chrome/test/base/ui_test_utils.cc index 7bb1acb..196b303 100644 --- a/chrome/test/base/ui_test_utils.cc +++ b/chrome/test/base/ui_test_utils.cc @@ -518,7 +518,7 @@ bool ExecuteJavaScript(RenderViewHost* render_view_host, const std::wstring& frame_xpath, const std::wstring& original_script) { std::wstring script = - original_script + L"window.domAutomationController.send(0);"; + original_script + L";window.domAutomationController.send(0);"; return ExecuteJavaScriptHelper(render_view_host, frame_xpath, script, NULL); } |