OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/string_number_conversions.h" | 5 #include "base/string_number_conversions.h" |
6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
7 #include "content/public/browser/browser_context.h" | 7 #include "content/public/browser/browser_context.h" |
8 #include "content/public/browser/download_manager.h" | 8 #include "content/public/browser/download_manager.h" |
9 #include "content/public/browser/notification_service.h" | 9 #include "content/public/browser/notification_service.h" |
10 #include "content/public/browser/notification_types.h" | 10 #include "content/public/browser/notification_types.h" |
11 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" |
12 #include "content/public/test/browser_test_utils.h" | 12 #include "content/public/test/browser_test_utils.h" |
13 #include "content/public/test/test_utils.h" | 13 #include "content/public/test/test_utils.h" |
14 #include "content/shell/shell.h" | 14 #include "content/shell/shell.h" |
15 #include "content/test/content_browser_test.h" | 15 #include "content/test/content_browser_test.h" |
16 #include "content/test/content_browser_test_utils.h" | 16 #include "content/test/content_browser_test_utils.h" |
17 #include "content/test/net/url_request_mock_http_job.h" | 17 #include "content/test/net/url_request_mock_http_job.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 | 19 |
20 namespace content { | 20 namespace content { |
21 | 21 |
22 class DatabaseTest : public ContentBrowserTest { | 22 class DatabaseTest : public ContentBrowserTest { |
23 public: | 23 public: |
24 DatabaseTest() {} | 24 DatabaseTest() {} |
25 | 25 |
26 void RunScriptAndCheckResult(Shell* shell, | 26 void RunScriptAndCheckResult(Shell* shell, |
27 const std::string& script, | 27 const std::string& script, |
28 const std::string& result) { | 28 const std::string& result) { |
29 std::string data; | 29 std::string data; |
30 ASSERT_TRUE(ExecuteJavaScriptAndExtractString( | 30 ASSERT_TRUE(ExecuteScriptAndExtractString( |
31 shell->web_contents()->GetRenderViewHost(), | 31 shell->web_contents(), |
32 std::string(), | |
33 script, | 32 script, |
34 &data)); | 33 &data)); |
35 ASSERT_EQ(data, result); | 34 ASSERT_EQ(data, result); |
36 } | 35 } |
37 | 36 |
38 void Navigate(Shell* shell) { | 37 void Navigate(Shell* shell) { |
39 NavigateToURL(shell, GetTestUrl("", "simple_database.html")); | 38 NavigateToURL(shell, GetTestUrl("", "simple_database.html")); |
40 } | 39 } |
41 | 40 |
42 void CreateTable(Shell* shell) { | 41 void CreateTable(Shell* shell) { |
(...skipping 15 matching lines...) Expand all Loading... |
58 RunScriptAndCheckResult( | 57 RunScriptAndCheckResult( |
59 shell, "deleteRecord(" + base::IntToString(index) + ")", "done"); | 58 shell, "deleteRecord(" + base::IntToString(index) + ")", "done"); |
60 } | 59 } |
61 | 60 |
62 void CompareRecords(Shell* shell, const std::string& expected) { | 61 void CompareRecords(Shell* shell, const std::string& expected) { |
63 RunScriptAndCheckResult(shell, "getRecords()", expected); | 62 RunScriptAndCheckResult(shell, "getRecords()", expected); |
64 } | 63 } |
65 | 64 |
66 bool HasTable(Shell* shell) { | 65 bool HasTable(Shell* shell) { |
67 std::string data; | 66 std::string data; |
68 CHECK(ExecuteJavaScriptAndExtractString( | 67 CHECK(ExecuteScriptAndExtractString( |
69 shell->web_contents()->GetRenderViewHost(), | 68 shell->web_contents(), |
70 std::string(), | |
71 "getRecords()", | 69 "getRecords()", |
72 &data)); | 70 &data)); |
73 return data != "getRecords error: [object SQLError]"; | 71 return data != "getRecords error: [object SQLError]"; |
74 } | 72 } |
75 }; | 73 }; |
76 | 74 |
77 // Insert records to the database. | 75 // Insert records to the database. |
78 IN_PROC_BROWSER_TEST_F(DatabaseTest, InsertRecord) { | 76 IN_PROC_BROWSER_TEST_F(DatabaseTest, InsertRecord) { |
79 Navigate(shell()); | 77 Navigate(shell()); |
80 CreateTable(shell()); | 78 CreateTable(shell()); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 Navigate(otr1); | 261 Navigate(otr1); |
264 CreateTable(otr1); | 262 CreateTable(otr1); |
265 InsertRecord(otr1, "text"); | 263 InsertRecord(otr1, "text"); |
266 | 264 |
267 Shell* otr2 = CreateOffTheRecordBrowser(); | 265 Shell* otr2 = CreateOffTheRecordBrowser(); |
268 Navigate(otr2); | 266 Navigate(otr2); |
269 CompareRecords(otr2, "text"); | 267 CompareRecords(otr2, "text"); |
270 } | 268 } |
271 | 269 |
272 } // namespace content | 270 } // namespace content |
OLD | NEW |