OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
7 #include "chrome/browser/browsing_data_database_helper.h" | 7 #include "chrome/browser/browsing_data_database_helper.h" |
8 #include "chrome/browser/browsing_data_helper_browsertest.h" | |
8 #include "chrome/browser/browser_thread.h" | 9 #include "chrome/browser/browser_thread.h" |
9 #include "chrome/test/in_process_browser_test.h" | 10 #include "chrome/test/in_process_browser_test.h" |
10 #include "chrome/test/testing_profile.h" | 11 #include "chrome/test/testing_profile.h" |
11 #include "chrome/test/ui_test_utils.h" | 12 #include "chrome/test/ui_test_utils.h" |
12 | 13 |
13 static const char kTestIdentifier1[] = "http_www.google.com_0"; | 14 namespace { |
bulach
2011/02/22 22:34:01
I think there's a \n here and when closing the nam
| |
15 typedef BrowsingDataHelperCallback<BrowsingDataDatabaseHelper::DatabaseInfo> | |
16 TestCompletionCallback; | |
14 | 17 |
15 static const char kTestIdentifierExtension[] = | 18 const char kTestIdentifier1[] = "http_www.google.com_0"; |
19 | |
20 const char kTestIdentifierExtension[] = | |
16 "chrome-extension_behllobkkfkfnphdnhnkndlbkcpglgmj_0"; | 21 "chrome-extension_behllobkkfkfnphdnhnkndlbkcpglgmj_0"; |
17 | 22 |
18 class BrowsingDataDatabaseHelperTest : public InProcessBrowserTest { | 23 class BrowsingDataDatabaseHelperTest : public InProcessBrowserTest { |
19 public: | 24 public: |
20 virtual void CreateDatabases() { | 25 virtual void CreateDatabases() { |
21 webkit_database::DatabaseTracker* db_tracker = | 26 webkit_database::DatabaseTracker* db_tracker = |
22 testing_profile_.GetDatabaseTracker(); | 27 testing_profile_.GetDatabaseTracker(); |
23 string16 db_name = ASCIIToUTF16("db"); | 28 string16 db_name = ASCIIToUTF16("db"); |
24 string16 description = ASCIIToUTF16("db_description"); | 29 string16 description = ASCIIToUTF16("db_description"); |
25 int64 size; | 30 int64 size; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 IN_PROC_BROWSER_TEST_F(BrowsingDataDatabaseHelperTest, FetchData) { | 79 IN_PROC_BROWSER_TEST_F(BrowsingDataDatabaseHelperTest, FetchData) { |
75 CreateDatabases(); | 80 CreateDatabases(); |
76 scoped_refptr<BrowsingDataDatabaseHelper> database_helper( | 81 scoped_refptr<BrowsingDataDatabaseHelper> database_helper( |
77 new BrowsingDataDatabaseHelper(&testing_profile_)); | 82 new BrowsingDataDatabaseHelper(&testing_profile_)); |
78 StopTestOnCallback stop_test_on_callback(database_helper); | 83 StopTestOnCallback stop_test_on_callback(database_helper); |
79 database_helper->StartFetching( | 84 database_helper->StartFetching( |
80 NewCallback(&stop_test_on_callback, &StopTestOnCallback::Callback)); | 85 NewCallback(&stop_test_on_callback, &StopTestOnCallback::Callback)); |
81 // Blocks until StopTestOnCallback::Callback is notified. | 86 // Blocks until StopTestOnCallback::Callback is notified. |
82 ui_test_utils::RunMessageLoop(); | 87 ui_test_utils::RunMessageLoop(); |
83 } | 88 } |
89 | |
90 IN_PROC_BROWSER_TEST_F(BrowsingDataDatabaseHelperTest, CannedAddDatabase) { | |
91 const GURL origin1("http://host1:1/"); | |
92 const GURL origin2("http://host2:1/"); | |
93 const char origin_str1[] = "http_host1_1"; | |
94 const char origin_str2[] = "http_host2_1"; | |
95 const char db1[] = "db1"; | |
96 const char db2[] = "db2"; | |
97 const char db3[] = "db3"; | |
98 | |
99 scoped_refptr<CannedBrowsingDataDatabaseHelper> helper( | |
100 new CannedBrowsingDataDatabaseHelper(&testing_profile_)); | |
101 helper->AddDatabase(origin1, db1, ""); | |
102 helper->AddDatabase(origin1, db2, ""); | |
103 helper->AddDatabase(origin2, db3, ""); | |
104 | |
105 TestCompletionCallback callback; | |
106 helper->StartFetching( | |
107 NewCallback(&callback, &TestCompletionCallback::callback)); | |
108 | |
109 std::vector<BrowsingDataDatabaseHelper::DatabaseInfo> result = | |
110 callback.result(); | |
111 | |
112 ASSERT_EQ(3u, result.size()); | |
113 EXPECT_STREQ(origin_str1, result[0].origin_identifier.c_str()); | |
114 EXPECT_STREQ(db1, result[0].database_name.c_str()); | |
115 EXPECT_STREQ(origin_str1, result[1].origin_identifier.c_str()); | |
116 EXPECT_STREQ(db2, result[1].database_name.c_str()); | |
117 EXPECT_STREQ(origin_str2, result[2].origin_identifier.c_str()); | |
118 EXPECT_STREQ(db3, result[2].database_name.c_str()); | |
119 } | |
120 | |
121 IN_PROC_BROWSER_TEST_F(BrowsingDataDatabaseHelperTest, CannedUnique) { | |
122 const GURL origin("http://host1:1/"); | |
123 const char origin_str[] = "http_host1_1"; | |
124 const char db[] = "db1"; | |
125 | |
126 scoped_refptr<CannedBrowsingDataDatabaseHelper> helper( | |
127 new CannedBrowsingDataDatabaseHelper(&testing_profile_)); | |
128 helper->AddDatabase(origin, db, ""); | |
129 helper->AddDatabase(origin, db, ""); | |
130 | |
131 TestCompletionCallback callback; | |
132 helper->StartFetching( | |
133 NewCallback(&callback, &TestCompletionCallback::callback)); | |
134 | |
135 std::vector<BrowsingDataDatabaseHelper::DatabaseInfo> result = | |
136 callback.result(); | |
137 | |
138 ASSERT_EQ(1u, result.size()); | |
139 EXPECT_STREQ(origin_str, result[0].origin_identifier.c_str()); | |
140 EXPECT_STREQ(db, result[0].database_name.c_str()); | |
141 } | |
bulach
2011/02/22 22:34:01
ditto
| |
142 } // namespace | |
OLD | NEW |