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

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

Issue 7601006: GTTF: Use a fresh TestingBrowserProcess for each test, part #5 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 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) 2011 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/browsing_data_helper_browsertest.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/browser.h"
9 #include "chrome/test/base/in_process_browser_test.h" 11 #include "chrome/test/base/in_process_browser_test.h"
10 #include "chrome/test/base/testing_profile.h"
11 #include "chrome/test/base/ui_test_utils.h" 12 #include "chrome/test/base/ui_test_utils.h"
12 #include "content/browser/browser_thread.h" 13 #include "content/browser/browser_thread.h"
13 14
14 namespace { 15 namespace {
15 typedef BrowsingDataHelperCallback<BrowsingDataDatabaseHelper::DatabaseInfo> 16 typedef BrowsingDataHelperCallback<BrowsingDataDatabaseHelper::DatabaseInfo>
16 TestCompletionCallback; 17 TestCompletionCallback;
17 18
18 const char kTestIdentifier1[] = "http_www.google.com_0"; 19 const char kTestIdentifier1[] = "http_www.google.com_0";
19 20
20 const char kTestIdentifierExtension[] = 21 const char kTestIdentifierExtension[] =
21 "chrome-extension_behllobkkfkfnphdnhnkndlbkcpglgmj_0"; 22 "chrome-extension_behllobkkfkfnphdnhnkndlbkcpglgmj_0";
22 23
23 class BrowsingDataDatabaseHelperTest : public InProcessBrowserTest { 24 class BrowsingDataDatabaseHelperTest : public InProcessBrowserTest {
24 public: 25 public:
25 virtual void CreateDatabases() { 26 virtual void CreateDatabases() {
26 webkit_database::DatabaseTracker* db_tracker = 27 webkit_database::DatabaseTracker* db_tracker =
27 testing_profile_.GetDatabaseTracker(); 28 browser()->profile()->GetDatabaseTracker();
28 string16 db_name = ASCIIToUTF16("db"); 29 string16 db_name = ASCIIToUTF16("db");
29 string16 description = ASCIIToUTF16("db_description"); 30 string16 description = ASCIIToUTF16("db_description");
30 int64 size; 31 int64 size;
31 string16 identifier1(UTF8ToUTF16(kTestIdentifier1)); 32 string16 identifier1(UTF8ToUTF16(kTestIdentifier1));
32 db_tracker->DatabaseOpened(identifier1, db_name, description, 1, &size); 33 db_tracker->DatabaseOpened(identifier1, db_name, description, 1, &size);
33 db_tracker->DatabaseClosed(identifier1, db_name); 34 db_tracker->DatabaseClosed(identifier1, db_name);
34 FilePath db_path1 = db_tracker->GetFullDBFilePath(identifier1, db_name); 35 FilePath db_path1 = db_tracker->GetFullDBFilePath(identifier1, db_name);
35 file_util::CreateDirectory(db_path1.DirName()); 36 file_util::CreateDirectory(db_path1.DirName());
36 ASSERT_EQ(0, file_util::WriteFile(db_path1, NULL, 0)); 37 ASSERT_EQ(0, file_util::WriteFile(db_path1, NULL, 0));
37 string16 identifierExtension(UTF8ToUTF16(kTestIdentifierExtension)); 38 string16 identifierExtension(UTF8ToUTF16(kTestIdentifierExtension));
38 db_tracker->DatabaseOpened(identifierExtension, db_name, description, 1, 39 db_tracker->DatabaseOpened(identifierExtension, db_name, description, 1,
39 &size); 40 &size);
40 db_tracker->DatabaseClosed(identifierExtension, db_name); 41 db_tracker->DatabaseClosed(identifierExtension, db_name);
41 FilePath db_path2 = 42 FilePath db_path2 =
42 db_tracker->GetFullDBFilePath(identifierExtension, db_name); 43 db_tracker->GetFullDBFilePath(identifierExtension, db_name);
43 file_util::CreateDirectory(db_path2.DirName()); 44 file_util::CreateDirectory(db_path2.DirName());
44 ASSERT_EQ(0, file_util::WriteFile(db_path2, NULL, 0)); 45 ASSERT_EQ(0, file_util::WriteFile(db_path2, NULL, 0));
45 std::vector<webkit_database::OriginInfo> origins; 46 std::vector<webkit_database::OriginInfo> origins;
46 db_tracker->GetAllOriginsInfo(&origins); 47 db_tracker->GetAllOriginsInfo(&origins);
47 ASSERT_EQ(2U, origins.size()); 48 ASSERT_EQ(2U, origins.size());
48 } 49 }
49
50 protected:
51 TestingProfile testing_profile_;
52 }; 50 };
53 51
54 // Called back by BrowsingDataDatabaseHelper on the UI thread once the database 52 // Called back by BrowsingDataDatabaseHelper on the UI thread once the database
55 // information has been retrieved. 53 // information has been retrieved.
56 class StopTestOnCallback { 54 class StopTestOnCallback {
57 public: 55 public:
58 explicit StopTestOnCallback( 56 explicit StopTestOnCallback(
59 BrowsingDataDatabaseHelper* database_helper) 57 BrowsingDataDatabaseHelper* database_helper)
60 : database_helper_(database_helper) { 58 : database_helper_(database_helper) {
61 DCHECK(database_helper_); 59 DCHECK(database_helper_);
62 } 60 }
63 61
64 void Callback(const std::vector<BrowsingDataDatabaseHelper::DatabaseInfo>& 62 void Callback(const std::vector<BrowsingDataDatabaseHelper::DatabaseInfo>&
65 database_info_list) { 63 database_info_list) {
66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
67 ASSERT_EQ(1UL, database_info_list.size()); 65 ASSERT_EQ(1UL, database_info_list.size());
68 EXPECT_EQ(std::string(kTestIdentifier1), 66 EXPECT_EQ(std::string(kTestIdentifier1),
69 database_info_list.at(0).origin_identifier); 67 database_info_list.at(0).origin_identifier);
70 MessageLoop::current()->Quit(); 68 MessageLoop::current()->Quit();
71 } 69 }
72 70
73 private: 71 private:
74 BrowsingDataDatabaseHelper* database_helper_; 72 BrowsingDataDatabaseHelper* database_helper_;
75 }; 73 };
76 74
77 IN_PROC_BROWSER_TEST_F(BrowsingDataDatabaseHelperTest, FetchData) { 75 IN_PROC_BROWSER_TEST_F(BrowsingDataDatabaseHelperTest, FetchData) {
78 CreateDatabases(); 76 CreateDatabases();
79 scoped_refptr<BrowsingDataDatabaseHelper> database_helper( 77 scoped_refptr<BrowsingDataDatabaseHelper> database_helper(
80 new BrowsingDataDatabaseHelper(&testing_profile_)); 78 new BrowsingDataDatabaseHelper(browser()->profile()));
81 StopTestOnCallback stop_test_on_callback(database_helper); 79 StopTestOnCallback stop_test_on_callback(database_helper);
82 database_helper->StartFetching( 80 database_helper->StartFetching(
83 NewCallback(&stop_test_on_callback, &StopTestOnCallback::Callback)); 81 NewCallback(&stop_test_on_callback, &StopTestOnCallback::Callback));
84 // Blocks until StopTestOnCallback::Callback is notified. 82 // Blocks until StopTestOnCallback::Callback is notified.
85 ui_test_utils::RunMessageLoop(); 83 ui_test_utils::RunMessageLoop();
86 } 84 }
87 85
88 IN_PROC_BROWSER_TEST_F(BrowsingDataDatabaseHelperTest, CannedAddDatabase) { 86 IN_PROC_BROWSER_TEST_F(BrowsingDataDatabaseHelperTest, CannedAddDatabase) {
89 const GURL origin1("http://host1:1/"); 87 const GURL origin1("http://host1:1/");
90 const GURL origin2("http://host2:1/"); 88 const GURL origin2("http://host2:1/");
91 const char origin_str1[] = "http_host1_1"; 89 const char origin_str1[] = "http_host1_1";
92 const char origin_str2[] = "http_host2_1"; 90 const char origin_str2[] = "http_host2_1";
93 const char db1[] = "db1"; 91 const char db1[] = "db1";
94 const char db2[] = "db2"; 92 const char db2[] = "db2";
95 const char db3[] = "db3"; 93 const char db3[] = "db3";
96 94
97 scoped_refptr<CannedBrowsingDataDatabaseHelper> helper( 95 scoped_refptr<CannedBrowsingDataDatabaseHelper> helper(
98 new CannedBrowsingDataDatabaseHelper(&testing_profile_)); 96 new CannedBrowsingDataDatabaseHelper(browser()->profile()));
99 helper->AddDatabase(origin1, db1, ""); 97 helper->AddDatabase(origin1, db1, "");
100 helper->AddDatabase(origin1, db2, ""); 98 helper->AddDatabase(origin1, db2, "");
101 helper->AddDatabase(origin2, db3, ""); 99 helper->AddDatabase(origin2, db3, "");
102 100
103 TestCompletionCallback callback; 101 TestCompletionCallback callback;
104 helper->StartFetching( 102 helper->StartFetching(
105 NewCallback(&callback, &TestCompletionCallback::callback)); 103 NewCallback(&callback, &TestCompletionCallback::callback));
106 104
107 std::vector<BrowsingDataDatabaseHelper::DatabaseInfo> result = 105 std::vector<BrowsingDataDatabaseHelper::DatabaseInfo> result =
108 callback.result(); 106 callback.result();
109 107
110 ASSERT_EQ(3u, result.size()); 108 ASSERT_EQ(3u, result.size());
111 EXPECT_STREQ(origin_str1, result[0].origin_identifier.c_str()); 109 EXPECT_STREQ(origin_str1, result[0].origin_identifier.c_str());
112 EXPECT_STREQ(db1, result[0].database_name.c_str()); 110 EXPECT_STREQ(db1, result[0].database_name.c_str());
113 EXPECT_STREQ(origin_str1, result[1].origin_identifier.c_str()); 111 EXPECT_STREQ(origin_str1, result[1].origin_identifier.c_str());
114 EXPECT_STREQ(db2, result[1].database_name.c_str()); 112 EXPECT_STREQ(db2, result[1].database_name.c_str());
115 EXPECT_STREQ(origin_str2, result[2].origin_identifier.c_str()); 113 EXPECT_STREQ(origin_str2, result[2].origin_identifier.c_str());
116 EXPECT_STREQ(db3, result[2].database_name.c_str()); 114 EXPECT_STREQ(db3, result[2].database_name.c_str());
117 } 115 }
118 116
119 IN_PROC_BROWSER_TEST_F(BrowsingDataDatabaseHelperTest, CannedUnique) { 117 IN_PROC_BROWSER_TEST_F(BrowsingDataDatabaseHelperTest, CannedUnique) {
120 const GURL origin("http://host1:1/"); 118 const GURL origin("http://host1:1/");
121 const char origin_str[] = "http_host1_1"; 119 const char origin_str[] = "http_host1_1";
122 const char db[] = "db1"; 120 const char db[] = "db1";
123 121
124 scoped_refptr<CannedBrowsingDataDatabaseHelper> helper( 122 scoped_refptr<CannedBrowsingDataDatabaseHelper> helper(
125 new CannedBrowsingDataDatabaseHelper(&testing_profile_)); 123 new CannedBrowsingDataDatabaseHelper(browser()->profile()));
126 helper->AddDatabase(origin, db, ""); 124 helper->AddDatabase(origin, db, "");
127 helper->AddDatabase(origin, db, ""); 125 helper->AddDatabase(origin, db, "");
128 126
129 TestCompletionCallback callback; 127 TestCompletionCallback callback;
130 helper->StartFetching( 128 helper->StartFetching(
131 NewCallback(&callback, &TestCompletionCallback::callback)); 129 NewCallback(&callback, &TestCompletionCallback::callback));
132 130
133 std::vector<BrowsingDataDatabaseHelper::DatabaseInfo> result = 131 std::vector<BrowsingDataDatabaseHelper::DatabaseInfo> result =
134 callback.result(); 132 callback.result();
135 133
136 ASSERT_EQ(1u, result.size()); 134 ASSERT_EQ(1u, result.size());
137 EXPECT_STREQ(origin_str, result[0].origin_identifier.c_str()); 135 EXPECT_STREQ(origin_str, result[0].origin_identifier.c_str());
138 EXPECT_STREQ(db, result[0].database_name.c_str()); 136 EXPECT_STREQ(db, result[0].database_name.c_str());
139 } 137 }
140 } // namespace 138 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/bookmarks/bookmark_node_data_unittest.cc ('k') | chrome/browser/browsing_data_indexed_db_helper_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698