Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: chrome/browser/browsing_data_database_helper_browsertest.cc

Issue 6246105: Only invoke WebKit methods in browsing data helpers on the WEBKIT thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/browser_thread.h" 8 #include "chrome/browser/browser_thread.h"
9 #include "chrome/test/in_process_browser_test.h" 9 #include "chrome/test/in_process_browser_test.h"
10 #include "chrome/test/testing_profile.h" 10 #include "chrome/test/testing_profile.h"
11 #include "chrome/test/ui_test_utils.h" 11 #include "chrome/test/ui_test_utils.h"
12 12
13 namespace {
13 static const char kTestIdentifier1[] = "http_www.google.com_0"; 14 static const char kTestIdentifier1[] = "http_www.google.com_0";
14 15
15 static const char kTestIdentifierExtension[] = 16 static const char kTestIdentifierExtension[] =
16 "chrome-extension_behllobkkfkfnphdnhnkndlbkcpglgmj_0"; 17 "chrome-extension_behllobkkfkfnphdnhnkndlbkcpglgmj_0";
17 18
19 class TestCompletionCallback {
Bernhard Bauer 2011/02/08 10:49:08 Do you think it would be complicated to pull this
20 public:
21 TestCompletionCallback()
22 : have_result_(false),
23 waiting_for_result_(false) {
24 }
25
26 const std::vector<BrowsingDataDatabaseHelper::DatabaseInfo>& result() {
27 WaitForResult();
28 return result_;
29 }
30
31 void callback(const std::vector<
32 BrowsingDataDatabaseHelper::DatabaseInfo>& info) {
33 have_result_ = true;
34 result_ = info;
35 if (waiting_for_result_)
Bernhard Bauer 2011/02/08 10:49:08 I think this is unnecessary. |MessageLoop::Quit| w
36 MessageLoop::current()->Quit();
37 }
38
39 private:
40 void WaitForResult() {
41 if (!have_result_) {
Bernhard Bauer 2011/02/08 10:49:08 That doesn't make sense now ;-) You should DCHECK
42 waiting_for_result_ = true;
43 MessageLoop::current()->Run();
44 waiting_for_result_ = false;
45 }
46 }
47
48 bool have_result_;
49 bool waiting_for_result_;
50 std::vector<BrowsingDataDatabaseHelper::DatabaseInfo> result_;
51
52 DISALLOW_COPY_AND_ASSIGN(TestCompletionCallback);
53 };
54 } // namespace
55
18 class BrowsingDataDatabaseHelperTest : public InProcessBrowserTest { 56 class BrowsingDataDatabaseHelperTest : public InProcessBrowserTest {
19 public: 57 public:
20 virtual void CreateDatabases() { 58 virtual void CreateDatabases() {
21 webkit_database::DatabaseTracker* db_tracker = 59 webkit_database::DatabaseTracker* db_tracker =
22 testing_profile_.GetDatabaseTracker(); 60 testing_profile_.GetDatabaseTracker();
23 string16 db_name = ASCIIToUTF16("db"); 61 string16 db_name = ASCIIToUTF16("db");
24 string16 description = ASCIIToUTF16("db_description"); 62 string16 description = ASCIIToUTF16("db_description");
25 int64 size; 63 int64 size;
26 int64 available; 64 int64 available;
27 string16 identifier1(UTF8ToUTF16(kTestIdentifier1)); 65 string16 identifier1(UTF8ToUTF16(kTestIdentifier1));
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 IN_PROC_BROWSER_TEST_F(BrowsingDataDatabaseHelperTest, FetchData) { 112 IN_PROC_BROWSER_TEST_F(BrowsingDataDatabaseHelperTest, FetchData) {
75 CreateDatabases(); 113 CreateDatabases();
76 scoped_refptr<BrowsingDataDatabaseHelper> database_helper( 114 scoped_refptr<BrowsingDataDatabaseHelper> database_helper(
77 new BrowsingDataDatabaseHelper(&testing_profile_)); 115 new BrowsingDataDatabaseHelper(&testing_profile_));
78 StopTestOnCallback stop_test_on_callback(database_helper); 116 StopTestOnCallback stop_test_on_callback(database_helper);
79 database_helper->StartFetching( 117 database_helper->StartFetching(
80 NewCallback(&stop_test_on_callback, &StopTestOnCallback::Callback)); 118 NewCallback(&stop_test_on_callback, &StopTestOnCallback::Callback));
81 // Blocks until StopTestOnCallback::Callback is notified. 119 // Blocks until StopTestOnCallback::Callback is notified.
82 ui_test_utils::RunMessageLoop(); 120 ui_test_utils::RunMessageLoop();
83 } 121 }
122
123 IN_PROC_BROWSER_TEST_F(BrowsingDataDatabaseHelperTest, CannedAddDatabase) {
124 const GURL origin1("http://host1:1/");
125 const GURL origin2("http://host2:1/");
126 const char origin_str1[] = "http_host1_1";
127 const char origin_str2[] = "http_host2_1";
128 const char db1[] = "db1";
129 const char db2[] = "db2";
130 const char db3[] = "db3";
131
132 scoped_refptr<CannedBrowsingDataDatabaseHelper> helper(
133 new CannedBrowsingDataDatabaseHelper(&testing_profile_));
134 helper->AddDatabase(origin1, db1, "");
135 helper->AddDatabase(origin1, db2, "");
136 helper->AddDatabase(origin2, db3, "");
137
138 TestCompletionCallback callback;
139 helper->StartFetching(
140 NewCallback(&callback, &TestCompletionCallback::callback));
141
142 std::vector<BrowsingDataDatabaseHelper::DatabaseInfo> result =
143 callback.result();
144
145 ASSERT_EQ(3u, result.size());
146 EXPECT_STREQ(origin_str1, result[0].origin_identifier.c_str());
147 EXPECT_STREQ(db1, result[0].database_name.c_str());
148 EXPECT_STREQ(origin_str1, result[1].origin_identifier.c_str());
149 EXPECT_STREQ(db2, result[1].database_name.c_str());
150 EXPECT_STREQ(origin_str2, result[2].origin_identifier.c_str());
151 EXPECT_STREQ(db3, result[2].database_name.c_str());
152 }
153
154 IN_PROC_BROWSER_TEST_F(BrowsingDataDatabaseHelperTest, CannedUnique) {
155 const GURL origin("http://host1:1/");
156 const char origin_str[] = "http_host1_1";
157 const char db[] = "db1";
158
159 scoped_refptr<CannedBrowsingDataDatabaseHelper> helper(
160 new CannedBrowsingDataDatabaseHelper(&testing_profile_));
161 helper->AddDatabase(origin, db, "");
162 helper->AddDatabase(origin, db, "");
163
164 TestCompletionCallback callback;
165 helper->StartFetching(
166 NewCallback(&callback, &TestCompletionCallback::callback));
167
168 std::vector<BrowsingDataDatabaseHelper::DatabaseInfo> result =
169 callback.result();
170
171 ASSERT_EQ(1u, result.size());
172 EXPECT_STREQ(origin_str, result[0].origin_identifier.c_str());
173 EXPECT_STREQ(db, result[0].database_name.c_str());
174 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698