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

Unified Diff: chrome/browser/browsing_data_indexed_db_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: Created 9 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/browsing_data_indexed_db_helper_browsertest.cc
diff --git a/chrome/browser/browsing_data_indexed_db_helper_browsertest.cc b/chrome/browser/browsing_data_indexed_db_helper_browsertest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0ee3a05ac5cc406680c75afe53c31be52253c205
--- /dev/null
+++ b/chrome/browser/browsing_data_indexed_db_helper_browsertest.cc
@@ -0,0 +1,109 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/callback.h"
+#include "base/file_path.h"
+#include "base/message_loop.h"
+#include "base/ref_counted.h"
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/browsing_data_indexed_db_helper.h"
+#include "chrome/test/in_process_browser_test.h"
+#include "chrome/test/testing_profile.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+class TestCompletionCallback {
+ public:
+ TestCompletionCallback()
+ : have_result_(false),
+ waiting_for_result_(false) {
+ }
+
+ const std::vector<BrowsingDataIndexedDBHelper::IndexedDBInfo>& result()
+ {
+ WaitForResult();
+ return result_;
+ }
+
+ void callback(const std::vector<
+ BrowsingDataIndexedDBHelper::IndexedDBInfo>& info) {
+ have_result_ = true;
+ result_ = info;
+ if (waiting_for_result_)
+ MessageLoop::current()->Quit();
+ }
+
+ private:
+ void WaitForResult() {
+ while (!have_result_) {
Paweł Hajdan Jr. 2011/02/05 12:44:51 Is this loop needed? Generally we should only run
+ waiting_for_result_ = true;
+ MessageLoop::current()->Run();
+ waiting_for_result_ = false;
+ }
+ }
+
+ bool have_result_;
+ bool waiting_for_result_;
+ std::vector<BrowsingDataIndexedDBHelper::IndexedDBInfo> result_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestCompletionCallback);
+};
+} // namespace
+
+
+class BrowsingDataIndexedDBHelperTest : public InProcessBrowserTest {
+ protected:
+ TestingProfile testing_profile_;
+};
+
+IN_PROC_BROWSER_TEST_F(BrowsingDataIndexedDBHelperTest, CannedAddIndexedDB) {
+ const GURL origin1("http://host1:1/");
+ const GURL origin2("http://host2:1/");
+ const string16 description(ASCIIToUTF16("description"));
+ const FilePath::CharType file1[] =
+ FILE_PATH_LITERAL("http_host1_1.indexeddb");
+ const FilePath::CharType file2[] =
+ FILE_PATH_LITERAL("http_host2_1.indexeddb");
+
+ scoped_refptr<CannedBrowsingDataIndexedDBHelper> helper(
+ new CannedBrowsingDataIndexedDBHelper(&testing_profile_));
+ helper->AddIndexedDB(origin1, description);
+ helper->AddIndexedDB(origin2, description);
+
+ TestCompletionCallback callback;
+ helper->StartFetching(
+ NewCallback(&callback, &TestCompletionCallback::callback));
+
+ std::vector<BrowsingDataIndexedDBHelper::IndexedDBInfo> result =
+ callback.result();
+
+ ASSERT_EQ(2U, result.size());
+ EXPECT_EQ(FilePath(file1).value(), result[0].file_path.BaseName().value());
+ EXPECT_EQ(FilePath(file2).value(), result[1].file_path.BaseName().value());
+}
+
+IN_PROC_BROWSER_TEST_F(BrowsingDataIndexedDBHelperTest, CannedUnique) {
+ const GURL origin("http://host1:1/");
+ const string16 description(ASCIIToUTF16("description"));
+ const FilePath::CharType file[] =
+ FILE_PATH_LITERAL("http_host1_1.indexeddb");
+
+ scoped_refptr<CannedBrowsingDataIndexedDBHelper> helper(
+ new CannedBrowsingDataIndexedDBHelper(&testing_profile_));
+ helper->AddIndexedDB(origin, description);
+ helper->AddIndexedDB(origin, description);
+
+ TestCompletionCallback callback;
+ helper->StartFetching(
+ NewCallback(&callback, &TestCompletionCallback::callback));
+
+ std::vector<BrowsingDataIndexedDBHelper::IndexedDBInfo> result =
+ callback.result();
+
+ ASSERT_EQ(1U, result.size());
+ EXPECT_EQ(FilePath(file).value(), result[0].file_path.BaseName().value());
+}

Powered by Google App Engine
This is Rietveld 408576698