diff options
author | Ben Murdoch <benm@google.com> | 2010-07-29 17:14:53 +0100 |
---|---|---|
committer | Ben Murdoch <benm@google.com> | 2010-08-04 14:29:45 +0100 |
commit | c407dc5cd9bdc5668497f21b26b09d988ab439de (patch) | |
tree | 7eaf8707c0309516bdb042ad976feedaf72b0bb1 /chrome/browser/browsing_data_local_storage_helper_unittest.cc | |
parent | 0998b1cdac5733f299c12d88bc31ef9c8035b8fa (diff) | |
download | external_chromium-c407dc5cd9bdc5668497f21b26b09d988ab439de.zip external_chromium-c407dc5cd9bdc5668497f21b26b09d988ab439de.tar.gz external_chromium-c407dc5cd9bdc5668497f21b26b09d988ab439de.tar.bz2 |
Merge Chromium src@r53293
Change-Id: Ia79acf8670f385cee48c45b0a75371d8e950af34
Diffstat (limited to 'chrome/browser/browsing_data_local_storage_helper_unittest.cc')
-rw-r--r-- | chrome/browser/browsing_data_local_storage_helper_unittest.cc | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/chrome/browser/browsing_data_local_storage_helper_unittest.cc b/chrome/browser/browsing_data_local_storage_helper_unittest.cc new file mode 100644 index 0000000..37c3555 --- /dev/null +++ b/chrome/browser/browsing_data_local_storage_helper_unittest.cc @@ -0,0 +1,89 @@ +// Copyright (c) 2010 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 "chrome/browser/browsing_data_local_storage_helper.h" + +#include "chrome/test/testing_profile.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace { +class TestCompletionCallback + : public CallbackRunner<Tuple1<const std::vector< + BrowsingDataLocalStorageHelper::LocalStorageInfo>& > > { + public: + TestCompletionCallback() + : have_result_(false) { + } + + bool have_result() const { return have_result_; } + + const std::vector<BrowsingDataLocalStorageHelper::LocalStorageInfo>& result() + { + return result_; + } + + virtual void RunWithParams( + const Tuple1<const std::vector< + BrowsingDataLocalStorageHelper::LocalStorageInfo>& >& params) { + have_result_ = true; + result_ = params.a; + } + + private: + bool have_result_; + std::vector<BrowsingDataLocalStorageHelper::LocalStorageInfo> result_; + + DISALLOW_COPY_AND_ASSIGN(TestCompletionCallback); +}; +} // namespace + +TEST(CannedBrowsingDataLocalStorageTest, AddLocalStorage) { + TestingProfile profile; + + const GURL origin1("http://host1:1/"); + const GURL origin2("http://host2:1/"); + const FilePath::CharType file1[] = + FILE_PATH_LITERAL("http_host1_1.localstorage"); + const FilePath::CharType file2[] = + FILE_PATH_LITERAL("http_host2_1.localstorage"); + + scoped_refptr<CannedBrowsingDataLocalStorageHelper> helper = + new CannedBrowsingDataLocalStorageHelper(&profile); + helper->AddLocalStorage(origin1); + helper->AddLocalStorage(origin2); + + TestCompletionCallback callback; + helper->StartFetching(&callback); + ASSERT_TRUE(callback.have_result()); + + std::vector<BrowsingDataLocalStorageHelper::LocalStorageInfo> 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()); +} + +TEST(CannedBrowsingDataLocalStorageTest, Unique) { + TestingProfile profile; + + const GURL origin("http://host1:1/"); + const FilePath::CharType file[] = + FILE_PATH_LITERAL("http_host1_1.localstorage"); + + scoped_refptr<CannedBrowsingDataLocalStorageHelper> helper = + new CannedBrowsingDataLocalStorageHelper(&profile); + helper->AddLocalStorage(origin); + helper->AddLocalStorage(origin); + + TestCompletionCallback callback; + helper->StartFetching(&callback); + ASSERT_TRUE(callback.have_result()); + + std::vector<BrowsingDataLocalStorageHelper::LocalStorageInfo> result = + callback.result(); + + ASSERT_EQ(1u, result.size()); + EXPECT_EQ(FilePath(file).value(), result[0].file_path.BaseName().value()); +} |