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