Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / test / perf / indexeddb_uitest.cc
blobf6e40669c4691258895a44d82383cb0a0ef710de
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.
5 #include "base/files/file_path.h"
6 #include "base/path_service.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "base/test/test_timeouts.h"
9 #include "chrome/common/automation_constants.h"
10 #include "chrome/common/chrome_paths.h"
11 #include "chrome/test/automation/tab_proxy.h"
12 #include "chrome/test/perf/perf_test.h"
13 #include "chrome/test/ui/javascript_test_util.h"
14 #include "chrome/test/ui/ui_perf_test.h"
15 #include "net/base/net_util.h"
16 #include "testing/perf/perf_test.h"
17 #include "url/gurl.h"
19 namespace {
21 static const base::FilePath::CharType kStartFile[] =
22 FILE_PATH_LITERAL("perf_test.html");
24 class IndexedDBTest : public UIPerfTest {
25 public:
26 typedef std::map<std::string, std::string> ResultsMap;
28 IndexedDBTest() : reference_(false) {
29 dom_automation_enabled_ = true;
30 show_window_ = true;
33 void RunTest() {
34 base::FilePath::StringType start_file(kStartFile);
35 base::FilePath test_path = GetIndexedDBTestDir();
36 test_path = test_path.Append(start_file);
37 GURL test_url(net::FilePathToFileURL(test_path));
39 scoped_refptr<TabProxy> tab(GetActiveTab());
40 ASSERT_TRUE(tab.get());
41 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(test_url));
43 // Wait for the test to finish.
44 ASSERT_TRUE(WaitUntilTestCompletes(tab.get(), test_url));
46 PrintResults(tab.get());
49 protected:
50 bool reference_; // True if this is a reference build.
52 private:
53 // Return the path to the IndexedDB test directory on the local filesystem.
54 base::FilePath GetIndexedDBTestDir() {
55 base::FilePath test_dir;
56 PathService::Get(chrome::DIR_TEST_DATA, &test_dir);
57 return test_dir.AppendASCII("indexeddb");
60 bool WaitUntilTestCompletes(TabProxy* tab, const GURL& test_url) {
61 return WaitUntilCookieValue(tab, test_url, "__done",
62 TestTimeouts::large_test_timeout(), "1");
65 bool GetResults(TabProxy* tab, ResultsMap* results) {
66 std::wstring json_wide;
67 bool succeeded = tab->ExecuteAndExtractString(
68 std::wstring(),
69 L"window.domAutomationController.send("
70 L" JSON.stringify(automation.getResults()));",
71 &json_wide);
73 EXPECT_TRUE(succeeded);
74 if (!succeeded)
75 return false;
77 std::string json = base::WideToUTF8(json_wide);
78 return JsonDictionaryToMap(json, results);
81 void PrintResults(TabProxy* tab) {
82 ResultsMap results;
83 ASSERT_TRUE(GetResults(tab, &results));
85 std::string trace_name = reference_ ? "t_ref" : "t";
87 ResultsMap::const_iterator it = results.begin();
88 for (; it != results.end(); ++it)
89 perf_test::PrintResultList(
90 it->first, std::string(), trace_name, it->second, "ms", false);
93 DISALLOW_COPY_AND_ASSIGN(IndexedDBTest);
96 class IndexedDBReferenceTest : public IndexedDBTest {
97 public:
98 IndexedDBReferenceTest() : IndexedDBTest() {
99 reference_ = true;
102 virtual void SetUp() {
103 UseReferenceBuild();
104 IndexedDBTest::SetUp();
108 TEST_F(IndexedDBTest, Perf) {
110 RunTest();
113 TEST_F(IndexedDBReferenceTest, Perf) {
115 RunTest();
118 } // namespace