1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/browser.h"
6 #include "chrome/browser/ui/tabs/tab_strip_model.h"
7 #include "chrome/test/base/in_process_browser_test.h"
8 #include "chrome/test/base/ui_test_utils.h"
9 #include "content/public/browser/web_contents.h"
10 #include "content/public/test/browser_test.h"
11 #include "content/public/test/browser_test_utils.h"
12 #include "net/test/embedded_test_server/embedded_test_server.h"
14 class LoadtimesExtensionBindingsTest : public InProcessBrowserTest {
16 LoadtimesExtensionBindingsTest() {}
18 void CompareBeforeAndAfter() {
19 // TODO(simonjam): There's a race on whether or not first paint is populated
20 // before we read them. We ought to test that too. Until the race is fixed,
21 // zero it out so the test is stable.
22 content::WebContents* contents =
23 browser()->tab_strip_model()->GetActiveWebContents();
24 ASSERT_TRUE(content::ExecuteScript(
26 "window.before.firstPaintAfterLoadTime = 0;"
27 "window.before.firstPaintTime = 0;"
28 "window.after.firstPaintAfterLoadTime = 0;"
29 "window.after.firstPaintTime = 0;"));
33 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
35 "window.domAutomationController.send("
36 " JSON.stringify(before))",
38 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
40 "window.domAutomationController.send("
41 " JSON.stringify(after))",
43 EXPECT_EQ(before, after);
47 IN_PROC_BROWSER_TEST_F(LoadtimesExtensionBindingsTest,
48 LoadTimesSameAfterClientInDocNavigation) {
49 ASSERT_TRUE(embedded_test_server()->Start());
50 GURL plain_url = embedded_test_server()->GetURL("/simple.html");
51 ui_test_utils::NavigateToURL(browser(), plain_url);
52 content::WebContents* contents =
53 browser()->tab_strip_model()->GetActiveWebContents();
54 ASSERT_TRUE(content::ExecuteScript(
55 contents, "window.before = window.chrome.loadTimes()"));
56 ASSERT_TRUE(content::ExecuteScript(
57 contents, "window.location.href = window.location + \"#\""));
58 ASSERT_TRUE(content::ExecuteScript(
59 contents, "window.after = window.chrome.loadTimes()"));
60 CompareBeforeAndAfter();
63 IN_PROC_BROWSER_TEST_F(LoadtimesExtensionBindingsTest,
64 LoadTimesSameAfterUserInDocNavigation) {
65 ASSERT_TRUE(embedded_test_server()->Start());
66 GURL plain_url = embedded_test_server()->GetURL("/simple.html");
67 GURL hash_url(plain_url.spec() + "#");
68 ui_test_utils::NavigateToURL(browser(), plain_url);
69 content::WebContents* contents =
70 browser()->tab_strip_model()->GetActiveWebContents();
71 ASSERT_TRUE(content::ExecuteScript(
72 contents, "window.before = window.chrome.loadTimes()"));
73 ui_test_utils::NavigateToURL(browser(), hash_url);
74 ASSERT_TRUE(content::ExecuteScript(
75 contents, "window.after = window.chrome.loadTimes()"));
76 CompareBeforeAndAfter();