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. 4 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_utils.h" 11 #include "net/test/embedded_test_server/embedded_test_server.h" 12 13 class LoadtimesExtensionBindingsTest : public InProcessBrowserTest { 14 public: 15 LoadtimesExtensionBindingsTest() {} 16 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::WebContents* contents = 22 browser()->tab_strip_model()->GetActiveWebContents(); 23 ASSERT_TRUE(content::ExecuteScript( 24 contents, 25 "window.before.firstPaintAfterLoadTime = 0;" 26 "window.before.firstPaintTime = 0;" 27 "window.after.firstPaintAfterLoadTime = 0;" 28 "window.after.firstPaintTime = 0;")); 29 30 std::string before; 31 std::string after; 32 ASSERT_TRUE(content::ExecuteScriptAndExtractString( 33 contents, 34 "window.domAutomationController.send(" 35 " JSON.stringify(before))", 36 &before)); 37 ASSERT_TRUE(content::ExecuteScriptAndExtractString( 38 contents, 39 "window.domAutomationController.send(" 40 " JSON.stringify(after))", 41 &after)); 42 EXPECT_EQ(before, after); 43 } 44 }; 45 46 IN_PROC_BROWSER_TEST_F(LoadtimesExtensionBindingsTest, 47 LoadTimesSameAfterClientInDocNavigation) { 48 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 49 GURL plain_url = embedded_test_server()->GetURL("/simple.html"); 50 ui_test_utils::NavigateToURL(browser(), plain_url); 51 content::WebContents* contents = 52 browser()->tab_strip_model()->GetActiveWebContents(); 53 ASSERT_TRUE(content::ExecuteScript( 54 contents, "window.before = window.chrome.loadTimes()")); 55 ASSERT_TRUE(content::ExecuteScript( 56 contents, "window.location.href = window.location + \"#\"")); 57 ASSERT_TRUE(content::ExecuteScript( 58 contents, "window.after = window.chrome.loadTimes()")); 59 CompareBeforeAndAfter(); 60 } 61 62 IN_PROC_BROWSER_TEST_F(LoadtimesExtensionBindingsTest, 63 LoadTimesSameAfterUserInDocNavigation) { 64 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 65 GURL plain_url = embedded_test_server()->GetURL("/simple.html"); 66 GURL hash_url(plain_url.spec() + "#"); 67 ui_test_utils::NavigateToURL(browser(), plain_url); 68 content::WebContents* contents = 69 browser()->tab_strip_model()->GetActiveWebContents(); 70 ASSERT_TRUE(content::ExecuteScript( 71 contents, "window.before = window.chrome.loadTimes()")); 72 ui_test_utils::NavigateToURL(browser(), hash_url); 73 ASSERT_TRUE(content::ExecuteScript( 74 contents, "window.after = window.chrome.loadTimes()")); 75 CompareBeforeAndAfter(); 76 } 77