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/browser_tabstrip.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_utils.h"
11 #include "net/test/test_server.h"
13 class LoadtimesExtensionBindingsTest
: public InProcessBrowserTest
{
15 LoadtimesExtensionBindingsTest() {}
17 void CompareBeforeAndAfter() {
18 // TODO(simonjam): There's a race on whether or not first paint is populated
19 // before we read them. We ought to test that too. Until the race is fixed,
20 // zero it out so the test is stable.
21 content::RenderViewHost
* rvh
=
22 chrome::GetActiveWebContents(browser())->GetRenderViewHost();
23 ASSERT_TRUE(content::ExecuteJavaScript(
25 L
"window.before.firstPaintAfterLoadTime = 0;"
26 L
"window.before.firstPaintTime = 0;"
27 L
"window.after.firstPaintAfterLoadTime = 0;"
28 L
"window.after.firstPaintTime = 0;"));
32 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString(
33 rvh
, L
"", L
"window.domAutomationController.send("
34 L
"JSON.stringify(before))", &before
));
35 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString(
36 rvh
, L
"", L
"window.domAutomationController.send("
37 L
"JSON.stringify(after))", &after
));
38 EXPECT_EQ(before
, after
);
42 IN_PROC_BROWSER_TEST_F(LoadtimesExtensionBindingsTest
,
43 LoadTimesSameAfterClientInDocNavigation
) {
44 ASSERT_TRUE(test_server()->Start());
45 GURL plain_url
= test_server()->GetURL("blank");
46 ui_test_utils::NavigateToURL(browser(), plain_url
);
47 content::RenderViewHost
* rvh
=
48 chrome::GetActiveWebContents(browser())->GetRenderViewHost();
49 ASSERT_TRUE(content::ExecuteJavaScript(
50 rvh
, L
"", L
"window.before = window.chrome.loadTimes()"));
51 ASSERT_TRUE(content::ExecuteJavaScript(
52 rvh
, L
"", L
"window.location.href = window.location + \"#\""));
53 ASSERT_TRUE(content::ExecuteJavaScript(
54 rvh
, L
"", L
"window.after = window.chrome.loadTimes()"));
55 CompareBeforeAndAfter();
58 IN_PROC_BROWSER_TEST_F(LoadtimesExtensionBindingsTest
,
59 LoadTimesSameAfterUserInDocNavigation
) {
60 ASSERT_TRUE(test_server()->Start());
61 GURL plain_url
= test_server()->GetURL("blank");
62 GURL
hash_url(plain_url
.spec() + "#");
63 ui_test_utils::NavigateToURL(browser(), plain_url
);
64 content::RenderViewHost
* rvh
=
65 chrome::GetActiveWebContents(browser())->GetRenderViewHost();
66 ASSERT_TRUE(content::ExecuteJavaScript(
67 rvh
, L
"", L
"window.before = window.chrome.loadTimes()"));
68 ui_test_utils::NavigateToURL(browser(), hash_url
);
69 ASSERT_TRUE(content::ExecuteJavaScript(
70 rvh
, L
"", L
"window.after = window.chrome.loadTimes()"));
71 CompareBeforeAndAfter();