[M120 Migration]Fix for crash during chrome exit
[platform/framework/web/chromium-efl.git] / chrome / browser / loadtimes_extension_bindings_browsertest.cc
1 // Copyright 2012 The Chromium Authors
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.h"
11 #include "content/public/test/browser_test_utils.h"
12 #include "net/test/embedded_test_server/embedded_test_server.h"
13
14 class LoadtimesExtensionBindingsTest : public InProcessBrowserTest {
15  public:
16   LoadtimesExtensionBindingsTest() {}
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.
22     content::WebContents* contents =
23         browser()->tab_strip_model()->GetActiveWebContents();
24     ASSERT_TRUE(content::ExecJs(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         content::EvalJs(contents, "JSON.stringify(before)").ExtractString();
32     std::string after =
33         content::EvalJs(contents, "JSON.stringify(after)").ExtractString();
34     EXPECT_EQ(before, after);
35   }
36 };
37
38 IN_PROC_BROWSER_TEST_F(LoadtimesExtensionBindingsTest,
39                        LoadTimesSameAfterClientInDocNavigation) {
40   ASSERT_TRUE(embedded_test_server()->Start());
41   GURL plain_url = embedded_test_server()->GetURL("/simple.html");
42   ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), plain_url));
43   content::WebContents* contents =
44       browser()->tab_strip_model()->GetActiveWebContents();
45   ASSERT_TRUE(
46       content::ExecJs(contents, "window.before = window.chrome.loadTimes()"));
47   ASSERT_TRUE(content::ExecJs(
48       contents, "window.location.href = window.location + \"#\""));
49   ASSERT_TRUE(
50       content::ExecJs(contents, "window.after = window.chrome.loadTimes()"));
51   CompareBeforeAndAfter();
52 }
53
54 IN_PROC_BROWSER_TEST_F(LoadtimesExtensionBindingsTest,
55                        LoadTimesSameAfterUserInDocNavigation) {
56   ASSERT_TRUE(embedded_test_server()->Start());
57   GURL plain_url = embedded_test_server()->GetURL("/simple.html");
58   GURL hash_url(plain_url.spec() + "#");
59   ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), plain_url));
60   content::WebContents* contents =
61       browser()->tab_strip_model()->GetActiveWebContents();
62   ASSERT_TRUE(
63       content::ExecJs(contents, "window.before = window.chrome.loadTimes()"));
64   ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), hash_url));
65   ASSERT_TRUE(
66       content::ExecJs(contents, "window.after = window.chrome.loadTimes()"));
67   CompareBeforeAndAfter();
68 }