Home | History | Annotate | Download | only in browser
      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
      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/memory/ref_counted.h"
     11 #include "base/message_loop.h"
     12 #include "base/utf_string_conversions.h"
     13 #include "chrome/browser/browsing_data_helper_browsertest.h"
     14 #include "chrome/browser/browsing_data_indexed_db_helper.h"
     15 #include "chrome/test/in_process_browser_test.h"
     16 #include "chrome/test/testing_profile.h"
     17 #include "testing/gtest/include/gtest/gtest.h"
     18 
     19 namespace {
     20 typedef BrowsingDataHelperCallback<BrowsingDataIndexedDBHelper::IndexedDBInfo>
     21     TestCompletionCallback;
     22 
     23 class BrowsingDataIndexedDBHelperTest : public InProcessBrowserTest {
     24  protected:
     25   TestingProfile testing_profile_;
     26 };
     27 
     28 IN_PROC_BROWSER_TEST_F(BrowsingDataIndexedDBHelperTest, CannedAddIndexedDB) {
     29   const GURL origin1("http://host1:1/");
     30   const GURL origin2("http://host2:1/");
     31   const string16 description(ASCIIToUTF16("description"));
     32   const FilePath::CharType file1[] =
     33       FILE_PATH_LITERAL("http_host1_1.indexeddb");
     34   const FilePath::CharType file2[] =
     35       FILE_PATH_LITERAL("http_host2_1.indexeddb");
     36 
     37   scoped_refptr<CannedBrowsingDataIndexedDBHelper> helper(
     38       new CannedBrowsingDataIndexedDBHelper(&testing_profile_));
     39   helper->AddIndexedDB(origin1, description);
     40   helper->AddIndexedDB(origin2, description);
     41 
     42   TestCompletionCallback callback;
     43   helper->StartFetching(
     44       NewCallback(&callback, &TestCompletionCallback::callback));
     45 
     46   std::vector<BrowsingDataIndexedDBHelper::IndexedDBInfo> result =
     47       callback.result();
     48 
     49   ASSERT_EQ(2U, result.size());
     50   EXPECT_EQ(FilePath(file1).value(), result[0].file_path.BaseName().value());
     51   EXPECT_EQ(FilePath(file2).value(), result[1].file_path.BaseName().value());
     52 }
     53 
     54 IN_PROC_BROWSER_TEST_F(BrowsingDataIndexedDBHelperTest, CannedUnique) {
     55   const GURL origin("http://host1:1/");
     56   const string16 description(ASCIIToUTF16("description"));
     57   const FilePath::CharType file[] =
     58       FILE_PATH_LITERAL("http_host1_1.indexeddb");
     59 
     60   scoped_refptr<CannedBrowsingDataIndexedDBHelper> helper(
     61       new CannedBrowsingDataIndexedDBHelper(&testing_profile_));
     62   helper->AddIndexedDB(origin, description);
     63   helper->AddIndexedDB(origin, description);
     64 
     65   TestCompletionCallback callback;
     66   helper->StartFetching(
     67       NewCallback(&callback, &TestCompletionCallback::callback));
     68 
     69   std::vector<BrowsingDataIndexedDBHelper::IndexedDBInfo> result =
     70       callback.result();
     71 
     72   ASSERT_EQ(1U, result.size());
     73   EXPECT_EQ(FilePath(file).value(), result[0].file_path.BaseName().value());
     74 }
     75 }  // namespace
     76