OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <string> |
| 6 |
| 7 #include "base/basictypes.h" |
| 8 #include "base/callback.h" |
| 9 #include "base/file_path.h" |
| 10 #include "base/message_loop.h" |
| 11 #include "base/ref_counted.h" |
| 12 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/browser/browsing_data_indexed_db_helper.h" |
| 14 #include "chrome/test/in_process_browser_test.h" |
| 15 #include "chrome/test/testing_profile.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 |
| 18 namespace { |
| 19 class TestCompletionCallback { |
| 20 public: |
| 21 TestCompletionCallback() |
| 22 : have_result_(false), |
| 23 waiting_for_result_(false) { |
| 24 } |
| 25 |
| 26 const std::vector<BrowsingDataIndexedDBHelper::IndexedDBInfo>& result() |
| 27 { |
| 28 WaitForResult(); |
| 29 return result_; |
| 30 } |
| 31 |
| 32 void callback(const std::vector< |
| 33 BrowsingDataIndexedDBHelper::IndexedDBInfo>& info) { |
| 34 have_result_ = true; |
| 35 result_ = info; |
| 36 if (waiting_for_result_) |
| 37 MessageLoop::current()->Quit(); |
| 38 } |
| 39 |
| 40 private: |
| 41 void WaitForResult() { |
| 42 if (!have_result_) { |
| 43 waiting_for_result_ = true; |
| 44 MessageLoop::current()->Run(); |
| 45 waiting_for_result_ = false; |
| 46 } |
| 47 } |
| 48 |
| 49 bool have_result_; |
| 50 bool waiting_for_result_; |
| 51 std::vector<BrowsingDataIndexedDBHelper::IndexedDBInfo> result_; |
| 52 |
| 53 DISALLOW_COPY_AND_ASSIGN(TestCompletionCallback); |
| 54 }; |
| 55 } // namespace |
| 56 |
| 57 |
| 58 class BrowsingDataIndexedDBHelperTest : public InProcessBrowserTest { |
| 59 protected: |
| 60 TestingProfile testing_profile_; |
| 61 }; |
| 62 |
| 63 IN_PROC_BROWSER_TEST_F(BrowsingDataIndexedDBHelperTest, CannedAddIndexedDB) { |
| 64 const GURL origin1("http://host1:1/"); |
| 65 const GURL origin2("http://host2:1/"); |
| 66 const string16 description(ASCIIToUTF16("description")); |
| 67 const FilePath::CharType file1[] = |
| 68 FILE_PATH_LITERAL("http_host1_1.indexeddb"); |
| 69 const FilePath::CharType file2[] = |
| 70 FILE_PATH_LITERAL("http_host2_1.indexeddb"); |
| 71 |
| 72 scoped_refptr<CannedBrowsingDataIndexedDBHelper> helper( |
| 73 new CannedBrowsingDataIndexedDBHelper(&testing_profile_)); |
| 74 helper->AddIndexedDB(origin1, description); |
| 75 helper->AddIndexedDB(origin2, description); |
| 76 |
| 77 TestCompletionCallback callback; |
| 78 helper->StartFetching( |
| 79 NewCallback(&callback, &TestCompletionCallback::callback)); |
| 80 |
| 81 std::vector<BrowsingDataIndexedDBHelper::IndexedDBInfo> result = |
| 82 callback.result(); |
| 83 |
| 84 ASSERT_EQ(2U, result.size()); |
| 85 EXPECT_EQ(FilePath(file1).value(), result[0].file_path.BaseName().value()); |
| 86 EXPECT_EQ(FilePath(file2).value(), result[1].file_path.BaseName().value()); |
| 87 } |
| 88 |
| 89 IN_PROC_BROWSER_TEST_F(BrowsingDataIndexedDBHelperTest, CannedUnique) { |
| 90 const GURL origin("http://host1:1/"); |
| 91 const string16 description(ASCIIToUTF16("description")); |
| 92 const FilePath::CharType file[] = |
| 93 FILE_PATH_LITERAL("http_host1_1.indexeddb"); |
| 94 |
| 95 scoped_refptr<CannedBrowsingDataIndexedDBHelper> helper( |
| 96 new CannedBrowsingDataIndexedDBHelper(&testing_profile_)); |
| 97 helper->AddIndexedDB(origin, description); |
| 98 helper->AddIndexedDB(origin, description); |
| 99 |
| 100 TestCompletionCallback callback; |
| 101 helper->StartFetching( |
| 102 NewCallback(&callback, &TestCompletionCallback::callback)); |
| 103 |
| 104 std::vector<BrowsingDataIndexedDBHelper::IndexedDBInfo> result = |
| 105 callback.result(); |
| 106 |
| 107 ASSERT_EQ(1U, result.size()); |
| 108 EXPECT_EQ(FilePath(file).value(), result[0].file_path.BaseName().value()); |
| 109 } |
OLD | NEW |