blob: 8f6e7c898a9528949323e4e0f0f1fea93b6c2a8e [file] [log] [blame]
[email protected]3e3b20d2012-04-18 01:09:541// 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]47ae23372013-01-29 01:50:486#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]3e3b20d2012-04-18 01:09:547#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 Kasting919ce652020-05-07 10:22:3610#include "content/public/test/browser_test.h"
[email protected]7d478cb2012-07-24 17:19:4211#include "content/public/test/browser_test_utils.h"
[email protected]c1dffe82013-06-26 20:59:0512#include "net/test/embedded_test_server/embedded_test_server.h"
[email protected]3e3b20d2012-04-18 01:09:5413
14class LoadtimesExtensionBindingsTest : public InProcessBrowserTest {
15 public:
[email protected]90ca44272012-07-18 18:15:4816 LoadtimesExtensionBindingsTest() {}
[email protected]3e3b20d2012-04-18 01:09:5417
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]47ae23372013-01-29 01:50:4822 content::WebContents* contents =
23 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]b6987e02013-01-04 18:30:4324 ASSERT_TRUE(content::ExecuteScript(
25 contents,
[email protected]06bc5d92013-01-02 22:44:1326 "window.before.firstPaintAfterLoadTime = 0;"
27 "window.before.firstPaintTime = 0;"
28 "window.after.firstPaintAfterLoadTime = 0;"
29 "window.after.firstPaintTime = 0;"));
[email protected]3e3b20d2012-04-18 01:09:5430
31 std::string before;
32 std::string after;
[email protected]b6987e02013-01-04 18:30:4333 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
34 contents,
[email protected]06bc5d92013-01-02 22:44:1335 "window.domAutomationController.send("
36 " JSON.stringify(before))",
37 &before));
[email protected]b6987e02013-01-04 18:30:4338 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
39 contents,
[email protected]06bc5d92013-01-02 22:44:1340 "window.domAutomationController.send("
41 " JSON.stringify(after))",
42 &after));
[email protected]3e3b20d2012-04-18 01:09:5443 EXPECT_EQ(before, after);
44 }
45};
46
47IN_PROC_BROWSER_TEST_F(LoadtimesExtensionBindingsTest,
48 LoadTimesSameAfterClientInDocNavigation) {
svaldeza01f7d92015-11-18 17:47:5649 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]c1dffe82013-06-26 20:59:0550 GURL plain_url = embedded_test_server()->GetURL("/simple.html");
Lukasz Anforowiczb78290c2021-09-08 04:31:3851 ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), plain_url));
[email protected]47ae23372013-01-29 01:50:4852 content::WebContents* contents =
53 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]b6987e02013-01-04 18:30:4354 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]3e3b20d2012-04-18 01:09:5460 CompareBeforeAndAfter();
61}
62
63IN_PROC_BROWSER_TEST_F(LoadtimesExtensionBindingsTest,
64 LoadTimesSameAfterUserInDocNavigation) {
svaldeza01f7d92015-11-18 17:47:5665 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]c1dffe82013-06-26 20:59:0566 GURL plain_url = embedded_test_server()->GetURL("/simple.html");
[email protected]3e3b20d2012-04-18 01:09:5467 GURL hash_url(plain_url.spec() + "#");
Lukasz Anforowiczb78290c2021-09-08 04:31:3868 ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), plain_url));
[email protected]47ae23372013-01-29 01:50:4869 content::WebContents* contents =
70 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]b6987e02013-01-04 18:30:4371 ASSERT_TRUE(content::ExecuteScript(
72 contents, "window.before = window.chrome.loadTimes()"));
Lukasz Anforowiczb78290c2021-09-08 04:31:3873 ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), hash_url));
[email protected]b6987e02013-01-04 18:30:4374 ASSERT_TRUE(content::ExecuteScript(
75 contents, "window.after = window.chrome.loadTimes()"));
[email protected]3e3b20d2012-04-18 01:09:5476 CompareBeforeAndAfter();
77}