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" |
(...skipping 10 matching lines...) Expand all Loading... |
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(ExecuteJavaScriptAndExtractString( |
31 shell->web_contents()->GetRenderViewHost(), L"", | 31 shell->web_contents()->GetRenderViewHost(), |
32 ASCIIToWide(script), &data)); | 32 std::string(), |
| 33 script, |
| 34 &data)); |
33 ASSERT_EQ(data, result); | 35 ASSERT_EQ(data, result); |
34 } | 36 } |
35 | 37 |
36 void Navigate(Shell* shell) { | 38 void Navigate(Shell* shell) { |
37 NavigateToURL(shell, GetTestUrl("", "simple_database.html")); | 39 NavigateToURL(shell, GetTestUrl("", "simple_database.html")); |
38 } | 40 } |
39 | 41 |
40 void CreateTable(Shell* shell) { | 42 void CreateTable(Shell* shell) { |
41 RunScriptAndCheckResult(shell, "createTable()", "done"); | 43 RunScriptAndCheckResult(shell, "createTable()", "done"); |
42 } | 44 } |
43 | 45 |
44 void InsertRecord(Shell* shell, const std::string& data) { | 46 void InsertRecord(Shell* shell, const std::string& data) { |
45 RunScriptAndCheckResult(shell, "insertRecord('" + data + "')", "done"); | 47 RunScriptAndCheckResult(shell, "insertRecord('" + data + "')", "done"); |
46 } | 48 } |
47 | 49 |
48 void UpdateRecord(Shell* shell, int index, const std::string& data) { | 50 void UpdateRecord(Shell* shell, int index, const std::string& data) { |
49 RunScriptAndCheckResult( | 51 RunScriptAndCheckResult( |
50 shell, "updateRecord(" + base::IntToString(index) + ", '" + data + "')", | 52 shell, |
51 "done"); | 53 "updateRecord(" + base::IntToString(index) + ", '" + data + "')", |
| 54 "done"); |
52 } | 55 } |
53 | 56 |
54 void DeleteRecord(Shell* shell, int index) { | 57 void DeleteRecord(Shell* shell, int index) { |
55 RunScriptAndCheckResult( | 58 RunScriptAndCheckResult( |
56 shell, "deleteRecord(" + base::IntToString(index) + ")", "done"); | 59 shell, "deleteRecord(" + base::IntToString(index) + ")", "done"); |
57 } | 60 } |
58 | 61 |
59 void CompareRecords(Shell* shell, const std::string& expected) { | 62 void CompareRecords(Shell* shell, const std::string& expected) { |
60 RunScriptAndCheckResult(shell, "getRecords()", expected); | 63 RunScriptAndCheckResult(shell, "getRecords()", expected); |
61 } | 64 } |
62 | 65 |
63 bool HasTable(Shell* shell) { | 66 bool HasTable(Shell* shell) { |
64 std::string data; | 67 std::string data; |
65 CHECK(ExecuteJavaScriptAndExtractString( | 68 CHECK(ExecuteJavaScriptAndExtractString( |
66 shell->web_contents()->GetRenderViewHost(), L"", | 69 shell->web_contents()->GetRenderViewHost(), |
67 ASCIIToWide("getRecords()"), &data)); | 70 std::string(), |
| 71 "getRecords()", |
| 72 &data)); |
68 return data != "getRecords error: [object SQLError]"; | 73 return data != "getRecords error: [object SQLError]"; |
69 } | 74 } |
70 }; | 75 }; |
71 | 76 |
72 // Insert records to the database. | 77 // Insert records to the database. |
73 IN_PROC_BROWSER_TEST_F(DatabaseTest, InsertRecord) { | 78 IN_PROC_BROWSER_TEST_F(DatabaseTest, InsertRecord) { |
74 Navigate(shell()); | 79 Navigate(shell()); |
75 CreateTable(shell()); | 80 CreateTable(shell()); |
76 InsertRecord(shell(), "text"); | 81 InsertRecord(shell(), "text"); |
77 CompareRecords(shell(), "text"); | 82 CompareRecords(shell(), "text"); |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 Navigate(otr1); | 263 Navigate(otr1); |
259 CreateTable(otr1); | 264 CreateTable(otr1); |
260 InsertRecord(otr1, "text"); | 265 InsertRecord(otr1, "text"); |
261 | 266 |
262 Shell* otr2 = CreateOffTheRecordBrowser(); | 267 Shell* otr2 = CreateOffTheRecordBrowser(); |
263 Navigate(otr2); | 268 Navigate(otr2); |
264 CompareRecords(otr2, "text"); | 269 CompareRecords(otr2, "text"); |
265 } | 270 } |
266 | 271 |
267 } // namespace content | 272 } // namespace content |
OLD | NEW |