OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/browser.h" | 5 #include "chrome/browser/ui/browser.h" |
6 #include "chrome/browser/ui/browser_tabstrip.h" | 6 #include "chrome/browser/ui/browser_tabstrip.h" |
7 #include "chrome/test/base/in_process_browser_test.h" | 7 #include "chrome/test/base/in_process_browser_test.h" |
8 #include "chrome/test/base/ui_test_utils.h" | 8 #include "chrome/test/base/ui_test_utils.h" |
9 #include "content/public/browser/web_contents.h" | 9 #include "content/public/browser/web_contents.h" |
10 #include "content/public/test/browser_test_utils.h" | 10 #include "content/public/test/browser_test_utils.h" |
11 #include "net/test/test_server.h" | 11 #include "net/test/test_server.h" |
12 | 12 |
13 class LoadtimesExtensionBindingsTest : public InProcessBrowserTest { | 13 class LoadtimesExtensionBindingsTest : public InProcessBrowserTest { |
14 public: | 14 public: |
15 LoadtimesExtensionBindingsTest() {} | 15 LoadtimesExtensionBindingsTest() {} |
16 | 16 |
17 void CompareBeforeAndAfter() { | 17 void CompareBeforeAndAfter() { |
18 // TODO(simonjam): There's a race on whether or not first paint is populated | 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, | 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. | 20 // zero it out so the test is stable. |
21 content::RenderViewHost* rvh = | 21 content::RenderViewHost* rvh = |
22 chrome::GetActiveWebContents(browser())->GetRenderViewHost(); | 22 chrome::GetActiveWebContents(browser())->GetRenderViewHost(); |
23 ASSERT_TRUE(content::ExecuteJavaScript( | 23 ASSERT_TRUE(content::ExecuteJavaScript( |
24 rvh, | 24 rvh, L"", |
25 "", | 25 L"window.before.firstPaintAfterLoadTime = 0;" |
26 "window.before.firstPaintAfterLoadTime = 0;" | 26 L"window.before.firstPaintTime = 0;" |
27 "window.before.firstPaintTime = 0;" | 27 L"window.after.firstPaintAfterLoadTime = 0;" |
28 "window.after.firstPaintAfterLoadTime = 0;" | 28 L"window.after.firstPaintTime = 0;")); |
29 "window.after.firstPaintTime = 0;")); | |
30 | 29 |
31 std::string before; | 30 std::string before; |
32 std::string after; | 31 std::string after; |
33 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( | 32 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( |
34 rvh, | 33 rvh, L"", L"window.domAutomationController.send(" |
35 "", | 34 L"JSON.stringify(before))", &before)); |
36 "window.domAutomationController.send(" | |
37 " JSON.stringify(before))", | |
38 &before)); | |
39 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( | 35 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( |
40 rvh, | 36 rvh, L"", L"window.domAutomationController.send(" |
41 "", | 37 L"JSON.stringify(after))", &after)); |
42 "window.domAutomationController.send(" | |
43 " JSON.stringify(after))", | |
44 &after)); | |
45 EXPECT_EQ(before, after); | 38 EXPECT_EQ(before, after); |
46 } | 39 } |
47 }; | 40 }; |
48 | 41 |
49 IN_PROC_BROWSER_TEST_F(LoadtimesExtensionBindingsTest, | 42 IN_PROC_BROWSER_TEST_F(LoadtimesExtensionBindingsTest, |
50 LoadTimesSameAfterClientInDocNavigation) { | 43 LoadTimesSameAfterClientInDocNavigation) { |
51 ASSERT_TRUE(test_server()->Start()); | 44 ASSERT_TRUE(test_server()->Start()); |
52 GURL plain_url = test_server()->GetURL("blank"); | 45 GURL plain_url = test_server()->GetURL("blank"); |
53 ui_test_utils::NavigateToURL(browser(), plain_url); | 46 ui_test_utils::NavigateToURL(browser(), plain_url); |
54 content::RenderViewHost* rvh = | 47 content::RenderViewHost* rvh = |
55 chrome::GetActiveWebContents(browser())->GetRenderViewHost(); | 48 chrome::GetActiveWebContents(browser())->GetRenderViewHost(); |
56 ASSERT_TRUE(content::ExecuteJavaScript( | 49 ASSERT_TRUE(content::ExecuteJavaScript( |
57 rvh, "", "window.before = window.chrome.loadTimes()")); | 50 rvh, L"", L"window.before = window.chrome.loadTimes()")); |
58 ASSERT_TRUE(content::ExecuteJavaScript( | 51 ASSERT_TRUE(content::ExecuteJavaScript( |
59 rvh, "", "window.location.href = window.location + \"#\"")); | 52 rvh, L"", L"window.location.href = window.location + \"#\"")); |
60 ASSERT_TRUE(content::ExecuteJavaScript( | 53 ASSERT_TRUE(content::ExecuteJavaScript( |
61 rvh, "", "window.after = window.chrome.loadTimes()")); | 54 rvh, L"", L"window.after = window.chrome.loadTimes()")); |
62 CompareBeforeAndAfter(); | 55 CompareBeforeAndAfter(); |
63 } | 56 } |
64 | 57 |
65 IN_PROC_BROWSER_TEST_F(LoadtimesExtensionBindingsTest, | 58 IN_PROC_BROWSER_TEST_F(LoadtimesExtensionBindingsTest, |
66 LoadTimesSameAfterUserInDocNavigation) { | 59 LoadTimesSameAfterUserInDocNavigation) { |
67 ASSERT_TRUE(test_server()->Start()); | 60 ASSERT_TRUE(test_server()->Start()); |
68 GURL plain_url = test_server()->GetURL("blank"); | 61 GURL plain_url = test_server()->GetURL("blank"); |
69 GURL hash_url(plain_url.spec() + "#"); | 62 GURL hash_url(plain_url.spec() + "#"); |
70 ui_test_utils::NavigateToURL(browser(), plain_url); | 63 ui_test_utils::NavigateToURL(browser(), plain_url); |
71 content::RenderViewHost* rvh = | 64 content::RenderViewHost* rvh = |
72 chrome::GetActiveWebContents(browser())->GetRenderViewHost(); | 65 chrome::GetActiveWebContents(browser())->GetRenderViewHost(); |
73 ASSERT_TRUE(content::ExecuteJavaScript( | 66 ASSERT_TRUE(content::ExecuteJavaScript( |
74 rvh, "", "window.before = window.chrome.loadTimes()")); | 67 rvh, L"", L"window.before = window.chrome.loadTimes()")); |
75 ui_test_utils::NavigateToURL(browser(), hash_url); | 68 ui_test_utils::NavigateToURL(browser(), hash_url); |
76 ASSERT_TRUE(content::ExecuteJavaScript( | 69 ASSERT_TRUE(content::ExecuteJavaScript( |
77 rvh, "", "window.after = window.chrome.loadTimes()")); | 70 rvh, L"", L"window.after = window.chrome.loadTimes()")); |
78 CompareBeforeAndAfter(); | 71 CompareBeforeAndAfter(); |
79 } | 72 } |
OLD | NEW |