Chromium Code Reviews| Index: chrome/browser/browsing_data_filesystem_helper_browsertest.cc |
| diff --git a/chrome/browser/browsing_data_filesystem_helper_browsertest.cc b/chrome/browser/browsing_data_filesystem_helper_browsertest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..793a476f67aa2dac586062550937a20f9fb88cad |
| --- /dev/null |
| +++ b/chrome/browser/browsing_data_filesystem_helper_browsertest.cc |
| @@ -0,0 +1,200 @@ |
| +// Copyright (c) 2011 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/memory/ref_counted.h" |
| +#include "base/message_loop.h" |
| +#include "base/utf_string_conversions.h" |
| +#include "chrome/browser/browsing_data_helper_browsertest.h" |
| +#include "chrome/browser/browsing_data_filesystem_helper.h" |
| +#include "chrome/test/in_process_browser_test.h" |
| +#include "chrome/test/testing_profile.h" |
| +#include "chrome/test/ui_test_utils.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +#include "content/browser/browser_thread.h" |
|
Paweł Hajdan Jr.
2011/05/24 16:30:31
nit: What's going on with those two separate group
Mike West
2011/05/24 16:53:51
Correct. It's an artifact of how I built the file
|
| +#include "webkit/fileapi/file_system_context.h" |
| +#include "webkit/fileapi/file_system_path_manager.h" |
| +#include "webkit/fileapi/sandbox_mount_point_provider.h" |
| +#include "webkit/fileapi/file_system_types.h" |
| + |
| +namespace { |
|
Paweł Hajdan Jr.
2011/05/24 16:30:31
nit: Add an empty line below.
Mike West
2011/05/24 16:53:51
Done.
|
| +typedef BrowsingDataHelperCallback<BrowsingDataFilesystemHelper::FilesystemInfo> |
| + TestCompletionCallback; |
| + |
| + |
|
Paweł Hajdan Jr.
2011/05/24 16:30:31
nit: Remove redundant empty line.
Mike West
2011/05/24 16:53:51
Done.
|
| +const char kTestOrigin1[] = "http://host1:1/"; |
| +const char kTestOrigin2[] = "http://host2:1/"; |
| +const char kTestOrigin3[] = "http://host3:1/"; |
| + |
| +const char kTestOriginExtension[] = |
| + "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj:1/"; |
| + |
| +class BrowsingDataFilesystemHelperTest : public InProcessBrowserTest { |
| + public: |
| + virtual void PopulateTestData() { |
| + const GURL origin1(kTestOrigin1); |
| + const GURL origin2(kTestOrigin2); |
| + const GURL origin3(kTestOrigin3); |
| + |
| + sandbox_ = testing_profile_.GetFileSystemContext()-> |
| + path_manager()->sandbox_provider(); |
| + |
| + CreateDirectoryForOriginAndType(origin1, fileapi::kFileSystemTypeTemporary); |
| + CreateDirectoryForOriginAndType(origin2, |
| + fileapi::kFileSystemTypePersistent); |
| + CreateDirectoryForOriginAndType(origin3, fileapi::kFileSystemTypeTemporary); |
| + CreateDirectoryForOriginAndType(origin3, |
| + fileapi::kFileSystemTypePersistent); |
| + } |
|
Paweł Hajdan Jr.
2011/05/24 16:30:31
nit: Add empty line below.
Mike West
2011/05/24 16:53:51
Done.
|
| + protected: |
| + void CreateDirectoryForOriginAndType(const GURL& origin, |
| + fileapi::FileSystemType type) { |
| + FilePath target = sandbox_->GetBaseDirectoryForOriginAndType(origin, |
| + type, true); |
| + file_util::CreateDirectory(target); |
|
Paweł Hajdan Jr.
2011/05/24 16:30:31
nit: Just check return value here instead of calli
Mike West
2011/05/24 16:53:51
Done.
|
| + ASSERT_TRUE(file_util::DirectoryExists(target)); |
| + } |
| + TestingProfile testing_profile_; |
| + fileapi::SandboxMountPointProvider* sandbox_; |
| +}; |
| + |
| +// Called back by BrowsingDataFilesystemHelper on the UI thread once the |
| +// database information has been retrieved. |
| +class StopTestOnCallback { |
| + public: |
| + explicit StopTestOnCallback( |
| + BrowsingDataFilesystemHelper* filesystem_helper) |
| + : filesystem_helper_(filesystem_helper) { |
| + DCHECK(filesystem_helper_); |
| + } |
| + |
| + void CallbackFetchData( |
| + const std::vector<BrowsingDataFilesystemHelper::FilesystemInfo>& |
| + filesystem_info_list) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + ASSERT_EQ(3UL, filesystem_info_list.size()); |
| + |
| + // Order is arbitrary, verify all three origins. |
| + bool test_hosts_found[3] = {false, false, false}; |
| + for (size_t i = 0; i < filesystem_info_list.size(); i++) { |
| + BrowsingDataFilesystemHelper::FilesystemInfo info = |
| + filesystem_info_list.at(i); |
| + if (info.origin == GURL(kTestOrigin1)) { |
| + test_hosts_found[0] = true; |
| + ASSERT_TRUE(info.has_temporary); |
| + ASSERT_FALSE(info.has_persistent); |
| + } else if (info.origin == GURL(kTestOrigin2)) { |
| + test_hosts_found[1] = true; |
| + ASSERT_FALSE(info.has_temporary); |
| + ASSERT_TRUE(info.has_persistent); |
| + } else if (info.origin == GURL(kTestOrigin3)) { |
| + test_hosts_found[2] = true; |
| + ASSERT_TRUE(info.has_temporary); |
| + ASSERT_TRUE(info.has_persistent); |
| + } else { |
| + NOTREACHED() << info.origin.spec() << " isn't an origin we added."; |
|
Paweł Hajdan Jr.
2011/05/24 16:30:31
Avoid NOTREACHED() in tests: only works in Debug m
Mike West
2011/05/24 16:53:51
I apparently did.
|
| + } |
| + } |
| + for (size_t i = 0; i < arraysize(test_hosts_found); i++) { |
| + ASSERT_TRUE(test_hosts_found[i]); |
| + } |
| + MessageLoop::current()->Quit(); |
| + } |
| + |
| + void CallbackDeleteData( |
| + const std::vector<BrowsingDataFilesystemHelper::FilesystemInfo>& |
| + filesystem_info_list) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + ASSERT_EQ(1UL, filesystem_info_list.size()); |
| + BrowsingDataFilesystemHelper::FilesystemInfo info = |
| + filesystem_info_list.at(0); |
| + ASSERT_EQ(info.origin, GURL(kTestOrigin3)); |
| + ASSERT_TRUE(info.has_temporary); |
| + ASSERT_TRUE(info.has_persistent); |
| + MessageLoop::current()->Quit(); |
| + } |
| + |
| + private: |
| + BrowsingDataFilesystemHelper* filesystem_helper_; |
| +}; |
| + |
| + |
| +IN_PROC_BROWSER_TEST_F(BrowsingDataFilesystemHelperTest, FetchData) { |
| + PopulateTestData(); |
| + scoped_refptr<BrowsingDataFilesystemHelper> filesystem_helper( |
| + BrowsingDataFilesystemHelper::Create(&testing_profile_)); |
| + StopTestOnCallback stop_test_on_callback(filesystem_helper); |
| + filesystem_helper->StartFetching( |
| + NewCallback(&stop_test_on_callback, |
| + &StopTestOnCallback::CallbackFetchData)); |
| + // Blocks until StopTestOnCallback::CallbackFetchData is notified. |
| + ui_test_utils::RunMessageLoop(); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(BrowsingDataFilesystemHelperTest, DeleteData) { |
| + PopulateTestData(); |
| + scoped_refptr<BrowsingDataFilesystemHelper> filesystem_helper( |
| + BrowsingDataFilesystemHelper::Create(&testing_profile_)); |
| + StopTestOnCallback stop_test_on_callback(filesystem_helper); |
| + filesystem_helper->DeleteFilesystemOrigin(GURL(kTestOrigin1)); |
| + filesystem_helper->DeleteFilesystemOrigin(GURL(kTestOrigin2)); |
| + filesystem_helper->StartFetching( |
| + NewCallback(&stop_test_on_callback, |
| + &StopTestOnCallback::CallbackDeleteData)); |
| + // Blocks until StopTestOnCallback::CallbackDeleteData is notified. |
| + ui_test_utils::RunMessageLoop(); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(BrowsingDataFilesystemHelperTest, CannedAddFilesystem) { |
| + const GURL origin1(kTestOrigin1); |
| + const GURL origin2(kTestOrigin2); |
| + |
| + scoped_refptr<CannedBrowsingDataFilesystemHelper> helper( |
| + new CannedBrowsingDataFilesystemHelper(&testing_profile_)); |
| + helper->AddFilesystem(origin1, fileapi::kFileSystemTypeTemporary); |
| + helper->AddFilesystem(origin2, fileapi::kFileSystemTypePersistent); |
| + |
| + TestCompletionCallback callback; |
| + helper->StartFetching( |
| + NewCallback(&callback, &TestCompletionCallback::callback)); |
| + |
| + std::vector<BrowsingDataFilesystemHelper::FilesystemInfo> result = |
| + callback.result(); |
| + |
| + ASSERT_EQ(2U, result.size()); |
| + ASSERT_EQ(origin1, result[0].origin); |
| + ASSERT_TRUE(result[0].has_temporary); |
| + ASSERT_FALSE(result[0].has_persistent); |
| + ASSERT_EQ(origin2, result[1].origin); |
| + ASSERT_FALSE(result[1].has_temporary); |
| + ASSERT_TRUE(result[1].has_persistent); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(BrowsingDataFilesystemHelperTest, CannedUnique) { |
| + const GURL origin3(kTestOrigin3); |
| + |
| + scoped_refptr<CannedBrowsingDataFilesystemHelper> helper( |
| + new CannedBrowsingDataFilesystemHelper(&testing_profile_)); |
| + helper->AddFilesystem(origin3, fileapi::kFileSystemTypePersistent); |
| + helper->AddFilesystem(origin3, fileapi::kFileSystemTypeTemporary); |
| + |
| + TestCompletionCallback callback; |
| + helper->StartFetching( |
| + NewCallback(&callback, &TestCompletionCallback::callback)); |
| + |
| + std::vector<BrowsingDataFilesystemHelper::FilesystemInfo> result = |
| + callback.result(); |
| + |
| + ASSERT_EQ(1U, result.size()); |
| + ASSERT_EQ(origin3, result[0].origin); |
| + ASSERT_TRUE(result[0].has_temporary); |
| + ASSERT_TRUE(result[0].has_persistent); |
| +} |
| + |
| +} // namespace |