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