[email protected] | 3e3b20d | 2012-04-18 01:09:54 | [diff] [blame] | 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" |
[email protected] | 47ae2337 | 2013-01-29 01:50:48 | [diff] [blame] | 6 | #include "chrome/browser/ui/tabs/tab_strip_model.h" |
[email protected] | 3e3b20d | 2012-04-18 01:09:54 | [diff] [blame] | 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" |
Peter Kasting | 919ce65 | 2020-05-07 10:22:36 | [diff] [blame] | 10 | #include "content/public/test/browser_test.h" |
[email protected] | 7d478cb | 2012-07-24 17:19:42 | [diff] [blame] | 11 | #include "content/public/test/browser_test_utils.h" |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 12 | #include "net/test/embedded_test_server/embedded_test_server.h" |
[email protected] | 3e3b20d | 2012-04-18 01:09:54 | [diff] [blame] | 13 | |
| 14 | class LoadtimesExtensionBindingsTest : public InProcessBrowserTest { |
| 15 | public: |
[email protected] | 90ca4427 | 2012-07-18 18:15:48 | [diff] [blame] | 16 | LoadtimesExtensionBindingsTest() {} |
[email protected] | 3e3b20d | 2012-04-18 01:09:54 | [diff] [blame] | 17 | |
| 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. |
[email protected] | 47ae2337 | 2013-01-29 01:50:48 | [diff] [blame] | 22 | content::WebContents* contents = |
| 23 | browser()->tab_strip_model()->GetActiveWebContents(); |
[email protected] | b6987e0 | 2013-01-04 18:30:43 | [diff] [blame] | 24 | ASSERT_TRUE(content::ExecuteScript( |
| 25 | contents, |
[email protected] | 06bc5d9 | 2013-01-02 22:44:13 | [diff] [blame] | 26 | "window.before.firstPaintAfterLoadTime = 0;" |
| 27 | "window.before.firstPaintTime = 0;" |
| 28 | "window.after.firstPaintAfterLoadTime = 0;" |
| 29 | "window.after.firstPaintTime = 0;")); |
[email protected] | 3e3b20d | 2012-04-18 01:09:54 | [diff] [blame] | 30 | |
| 31 | std::string before; |
| 32 | std::string after; |
[email protected] | b6987e0 | 2013-01-04 18:30:43 | [diff] [blame] | 33 | ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 34 | contents, |
[email protected] | 06bc5d9 | 2013-01-02 22:44:13 | [diff] [blame] | 35 | "window.domAutomationController.send(" |
| 36 | " JSON.stringify(before))", |
| 37 | &before)); |
[email protected] | b6987e0 | 2013-01-04 18:30:43 | [diff] [blame] | 38 | ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 39 | contents, |
[email protected] | 06bc5d9 | 2013-01-02 22:44:13 | [diff] [blame] | 40 | "window.domAutomationController.send(" |
| 41 | " JSON.stringify(after))", |
| 42 | &after)); |
[email protected] | 3e3b20d | 2012-04-18 01:09:54 | [diff] [blame] | 43 | EXPECT_EQ(before, after); |
| 44 | } |
| 45 | }; |
| 46 | |
| 47 | IN_PROC_BROWSER_TEST_F(LoadtimesExtensionBindingsTest, |
| 48 | LoadTimesSameAfterClientInDocNavigation) { |
svaldez | a01f7d9 | 2015-11-18 17:47:56 | [diff] [blame] | 49 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 50 | GURL plain_url = embedded_test_server()->GetURL("/simple.html"); |
Lukasz Anforowicz | b78290c | 2021-09-08 04:31:38 | [diff] [blame] | 51 | ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), plain_url)); |
[email protected] | 47ae2337 | 2013-01-29 01:50:48 | [diff] [blame] | 52 | content::WebContents* contents = |
| 53 | browser()->tab_strip_model()->GetActiveWebContents(); |
[email protected] | b6987e0 | 2013-01-04 18:30:43 | [diff] [blame] | 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()")); |
[email protected] | 3e3b20d | 2012-04-18 01:09:54 | [diff] [blame] | 60 | CompareBeforeAndAfter(); |
| 61 | } |
| 62 | |
| 63 | IN_PROC_BROWSER_TEST_F(LoadtimesExtensionBindingsTest, |
| 64 | LoadTimesSameAfterUserInDocNavigation) { |
svaldez | a01f7d9 | 2015-11-18 17:47:56 | [diff] [blame] | 65 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 66 | GURL plain_url = embedded_test_server()->GetURL("/simple.html"); |
[email protected] | 3e3b20d | 2012-04-18 01:09:54 | [diff] [blame] | 67 | GURL hash_url(plain_url.spec() + "#"); |
Lukasz Anforowicz | b78290c | 2021-09-08 04:31:38 | [diff] [blame] | 68 | ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), plain_url)); |
[email protected] | 47ae2337 | 2013-01-29 01:50:48 | [diff] [blame] | 69 | content::WebContents* contents = |
| 70 | browser()->tab_strip_model()->GetActiveWebContents(); |
[email protected] | b6987e0 | 2013-01-04 18:30:43 | [diff] [blame] | 71 | ASSERT_TRUE(content::ExecuteScript( |
| 72 | contents, "window.before = window.chrome.loadTimes()")); |
Lukasz Anforowicz | b78290c | 2021-09-08 04:31:38 | [diff] [blame] | 73 | ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), hash_url)); |
[email protected] | b6987e0 | 2013-01-04 18:30:43 | [diff] [blame] | 74 | ASSERT_TRUE(content::ExecuteScript( |
| 75 | contents, "window.after = window.chrome.loadTimes()")); |
[email protected] | 3e3b20d | 2012-04-18 01:09:54 | [diff] [blame] | 76 | CompareBeforeAndAfter(); |
| 77 | } |