1 // Copyright 2012 The Chromium Authors
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::ExecJs(contents,
25 "window.before.firstPaintAfterLoadTime = 0;"
26 "window.before.firstPaintTime = 0;"
27 "window.after.firstPaintAfterLoadTime = 0;"
28 "window.after.firstPaintTime = 0;"));
31 content::EvalJs(contents, "JSON.stringify(before)").ExtractString();
33 content::EvalJs(contents, "JSON.stringify(after)").ExtractString();
34 EXPECT_EQ(before, after);
38 IN_PROC_BROWSER_TEST_F(LoadtimesExtensionBindingsTest,
39 LoadTimesSameAfterClientInDocNavigation) {
40 ASSERT_TRUE(embedded_test_server()->Start());
41 GURL plain_url = embedded_test_server()->GetURL("/simple.html");
42 ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), plain_url));
43 content::WebContents* contents =
44 browser()->tab_strip_model()->GetActiveWebContents();
46 content::ExecJs(contents, "window.before = window.chrome.loadTimes()"));
47 ASSERT_TRUE(content::ExecJs(
48 contents, "window.location.href = window.location + \"#\""));
50 content::ExecJs(contents, "window.after = window.chrome.loadTimes()"));
51 CompareBeforeAndAfter();
54 IN_PROC_BROWSER_TEST_F(LoadtimesExtensionBindingsTest,
55 LoadTimesSameAfterUserInDocNavigation) {
56 ASSERT_TRUE(embedded_test_server()->Start());
57 GURL plain_url = embedded_test_server()->GetURL("/simple.html");
58 GURL hash_url(plain_url.spec() + "#");
59 ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), plain_url));
60 content::WebContents* contents =
61 browser()->tab_strip_model()->GetActiveWebContents();
63 content::ExecJs(contents, "window.before = window.chrome.loadTimes()"));
64 ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), hash_url));
66 content::ExecJs(contents, "window.after = window.chrome.loadTimes()"));
67 CompareBeforeAndAfter();