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

Side by Side Diff: chrome/browser/browsing_data_database_helper_unittest.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) 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 "chrome/browser/browsing_data_database_helper.h" 5 #include "chrome/browser/browsing_data_database_helper.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "chrome/test/testing_profile.h" 8 #include "chrome/test/testing_profile.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
11 namespace { 11 namespace {
bulach 2011/02/22 22:34:01 ditto
12 class TestCompletionCallback {
13 public:
14 TestCompletionCallback()
15 : have_result_(false) {
16 }
17
18 bool have_result() const { return have_result_; }
19
20 const std::vector<BrowsingDataDatabaseHelper::DatabaseInfo>& result() {
21 return result_;
22 }
23
24 void callback(const std::vector<
25 BrowsingDataDatabaseHelper::DatabaseInfo>& info) {
26 have_result_ = true;
27 result_ = info;
28 }
29
30 private:
31 bool have_result_;
32 std::vector<BrowsingDataDatabaseHelper::DatabaseInfo> result_;
33
34 DISALLOW_COPY_AND_ASSIGN(TestCompletionCallback);
35 };
36 } // namespace
37
38 TEST(CannedBrowsingDataDatabaseTest, AddDatabase) {
39 TestingProfile profile;
40
41 const GURL origin1("http://host1:1/");
42 const GURL origin2("http://host2:1/");
43 const char origin_str1[] = "http_host1_1";
44 const char origin_str2[] = "http_host2_1";
45 const char db1[] = "db1";
46 const char db2[] = "db2";
47 const char db3[] = "db3";
48
49 scoped_refptr<CannedBrowsingDataDatabaseHelper> helper(
50 new CannedBrowsingDataDatabaseHelper(&profile));
51 helper->AddDatabase(origin1, db1, "");
52 helper->AddDatabase(origin1, db2, "");
53 helper->AddDatabase(origin2, db3, "");
54
55 TestCompletionCallback callback;
56 helper->StartFetching(
57 NewCallback(&callback, &TestCompletionCallback::callback));
58 ASSERT_TRUE(callback.have_result());
59
60 std::vector<BrowsingDataDatabaseHelper::DatabaseInfo> result =
61 callback.result();
62
63 ASSERT_EQ(3u, result.size());
64 EXPECT_STREQ(origin_str1, result[0].origin_identifier.c_str());
65 EXPECT_STREQ(db1, result[0].database_name.c_str());
66 EXPECT_STREQ(origin_str1, result[1].origin_identifier.c_str());
67 EXPECT_STREQ(db2, result[1].database_name.c_str());
68 EXPECT_STREQ(origin_str2, result[2].origin_identifier.c_str());
69 EXPECT_STREQ(db3, result[2].database_name.c_str());
70 }
71
72 TEST(CannedBrowsingDataDatabaseTest, Unique) {
73 TestingProfile profile;
74
75 const GURL origin("http://host1:1/");
76 const char origin_str[] = "http_host1_1";
77 const char db[] = "db1";
78
79 scoped_refptr<CannedBrowsingDataDatabaseHelper> helper(
80 new CannedBrowsingDataDatabaseHelper(&profile));
81 helper->AddDatabase(origin, db, "");
82 helper->AddDatabase(origin, db, "");
83
84 TestCompletionCallback callback;
85 helper->StartFetching(
86 NewCallback(&callback, &TestCompletionCallback::callback));
87 ASSERT_TRUE(callback.have_result());
88
89 std::vector<BrowsingDataDatabaseHelper::DatabaseInfo> result =
90 callback.result();
91
92 ASSERT_EQ(1u, result.size());
93 EXPECT_STREQ(origin_str, result[0].origin_identifier.c_str());
94 EXPECT_STREQ(db, result[0].database_name.c_str());
95 }
96
97 TEST(CannedBrowsingDataDatabaseTest, Empty) { 12 TEST(CannedBrowsingDataDatabaseTest, Empty) {
98 TestingProfile profile; 13 TestingProfile profile;
99 14
100 const GURL origin("http://host1:1/"); 15 const GURL origin("http://host1:1/");
101 const char db[] = "db1"; 16 const char db[] = "db1";
102 17
103 scoped_refptr<CannedBrowsingDataDatabaseHelper> helper( 18 scoped_refptr<CannedBrowsingDataDatabaseHelper> helper(
104 new CannedBrowsingDataDatabaseHelper(&profile)); 19 new CannedBrowsingDataDatabaseHelper(&profile));
105 20
106 ASSERT_TRUE(helper->empty()); 21 ASSERT_TRUE(helper->empty());
107 helper->AddDatabase(origin, db, ""); 22 helper->AddDatabase(origin, db, "");
108 ASSERT_FALSE(helper->empty()); 23 ASSERT_FALSE(helper->empty());
109 helper->Reset(); 24 helper->Reset();
110 ASSERT_TRUE(helper->empty()); 25 ASSERT_TRUE(helper->empty());
111 } 26 }
bulach 2011/02/22 22:34:01 ditto
27 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698