summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/loadtimes_extension_bindings_uitest.cc
blob: a47ca9d129659a5ad504a51396dee0dffc61fa9e (plain)
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
73
// Copyright (c) 2011 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/test/automation/tab_proxy.h"
#include "chrome/test/ui/ui_test.h"
#include "googleurl/src/gurl.h"
#include "net/test/test_server.h"
#include "testing/gtest/include/gtest/gtest.h"

class LoadtimesExtensionBindingsUITest : public UITest {
 public:
  LoadtimesExtensionBindingsUITest()
      : http_server_(net::TestServer::TYPE_HTTP, FilePath()) {
    dom_automation_enabled_ = true;
  }

  void CompareBeforeAndAfter(TabProxy* tab_proxy) {
    // 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.
    ASSERT_TRUE(tab_proxy->ExecuteJavaScript(
        "window.before.firstPaintAfterLoadTime = 0;"
        "window.before.firstPaintTime = 0;"
        "window.after.firstPaintAfterLoadTime = 0;"
        "window.after.firstPaintTime = 0;"));

    std::wstring before;
    std::wstring after;
    ASSERT_TRUE(tab_proxy->ExecuteAndExtractString(
        L"", L"window.domAutomationController.send("
        L"JSON.stringify(before))", &before));
    ASSERT_TRUE(tab_proxy->ExecuteAndExtractString(
        L"", L"window.domAutomationController.send("
        L"JSON.stringify(after))", &after));
    EXPECT_EQ(before, after);
  }

 protected:
  net::TestServer http_server_;
};

TEST_F(LoadtimesExtensionBindingsUITest,
       LoadTimesSameAfterClientInDocNavigation) {
  ASSERT_TRUE(http_server_.Start());
  GURL plain_url = http_server_.GetURL("blank");
  NavigateToURL(plain_url);
  scoped_refptr<TabProxy> tab_proxy = GetActiveTab();
  ASSERT_TRUE(tab_proxy.get());
  ASSERT_TRUE(tab_proxy->ExecuteJavaScript(
      "window.before = window.chrome.loadTimes()"));
  ASSERT_TRUE(tab_proxy->ExecuteJavaScript(
      "window.location.href = window.location + \"#\""));
  ASSERT_TRUE(tab_proxy->ExecuteJavaScript(
      "window.after = window.chrome.loadTimes()"));
  CompareBeforeAndAfter(tab_proxy.get());
}

TEST_F(LoadtimesExtensionBindingsUITest,
       LoadTimesSameAfterUserInDocNavigation) {
  ASSERT_TRUE(http_server_.Start());
  GURL plain_url = http_server_.GetURL("blank");
  GURL hash_url(plain_url.spec() + "#");
  NavigateToURL(plain_url);
  scoped_refptr<TabProxy> tab_proxy = GetActiveTab();
  ASSERT_TRUE(tab_proxy.get());
  ASSERT_TRUE(tab_proxy->ExecuteJavaScript(
      "window.before = window.chrome.loadTimes()"));
  NavigateToURL(hash_url);
  ASSERT_TRUE(tab_proxy->ExecuteJavaScript(
      "window.after = window.chrome.loadTimes()"));
  CompareBeforeAndAfter(tab_proxy.get());
}