| 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(content::ExecuteJavaScriptAndExtractString( | 30 ASSERT_TRUE(ExecuteJavaScriptAndExtractString( |
| 31 shell->web_contents()->GetRenderViewHost(), L"", | 31 shell->web_contents()->GetRenderViewHost(), L"", |
| 32 ASCIIToWide(script), &data)); | 32 ASCIIToWide(script), &data)); |
| 33 ASSERT_EQ(data, result); | 33 ASSERT_EQ(data, result); |
| 34 } | 34 } |
| 35 | 35 |
| 36 void Navigate(Shell* shell) { | 36 void Navigate(Shell* shell) { |
| 37 NavigateToURL(shell, GetTestUrl("", "simple_database.html")); | 37 NavigateToURL(shell, GetTestUrl("", "simple_database.html")); |
| 38 } | 38 } |
| 39 | 39 |
| 40 void CreateTable(Shell* shell) { | 40 void CreateTable(Shell* shell) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 55 RunScriptAndCheckResult( | 55 RunScriptAndCheckResult( |
| 56 shell, "deleteRecord(" + base::IntToString(index) + ")", "done"); | 56 shell, "deleteRecord(" + base::IntToString(index) + ")", "done"); |
| 57 } | 57 } |
| 58 | 58 |
| 59 void CompareRecords(Shell* shell, const std::string& expected) { | 59 void CompareRecords(Shell* shell, const std::string& expected) { |
| 60 RunScriptAndCheckResult(shell, "getRecords()", expected); | 60 RunScriptAndCheckResult(shell, "getRecords()", expected); |
| 61 } | 61 } |
| 62 | 62 |
| 63 bool HasTable(Shell* shell) { | 63 bool HasTable(Shell* shell) { |
| 64 std::string data; | 64 std::string data; |
| 65 CHECK(content::ExecuteJavaScriptAndExtractString( | 65 CHECK(ExecuteJavaScriptAndExtractString( |
| 66 shell->web_contents()->GetRenderViewHost(), L"", | 66 shell->web_contents()->GetRenderViewHost(), L"", |
| 67 ASCIIToWide("getRecords()"), &data)); | 67 ASCIIToWide("getRecords()"), &data)); |
| 68 return data != "getRecords error: [object SQLError]"; | 68 return data != "getRecords error: [object SQLError]"; |
| 69 } | 69 } |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 // Insert records to the database. | 72 // Insert records to the database. |
| 73 IN_PROC_BROWSER_TEST_F(DatabaseTest, InsertRecord) { | 73 IN_PROC_BROWSER_TEST_F(DatabaseTest, InsertRecord) { |
| 74 Navigate(shell()); | 74 Navigate(shell()); |
| 75 CreateTable(shell()); | 75 CreateTable(shell()); |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 Navigate(otr1); | 258 Navigate(otr1); |
| 259 CreateTable(otr1); | 259 CreateTable(otr1); |
| 260 InsertRecord(otr1, "text"); | 260 InsertRecord(otr1, "text"); |
| 261 | 261 |
| 262 Shell* otr2 = CreateOffTheRecordBrowser(); | 262 Shell* otr2 = CreateOffTheRecordBrowser(); |
| 263 Navigate(otr2); | 263 Navigate(otr2); |
| 264 CompareRecords(otr2, "text"); | 264 CompareRecords(otr2, "text"); |
| 265 } | 265 } |
| 266 | 266 |
| 267 } // namespace content | 267 } // namespace content |
| OLD | NEW |