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

Side by Side Diff: chrome/browser/extensions/api/file_system/file_system_apitest_chromeos.cc

Issue 137463006: Add tests for Google Drive integration in chrome.fileSystem API on Chrome OS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
hashimoto 2014/01/15 10:43:15 nit: "(c)" is not needed.
kinaba 2014/01/16 01:36:09 Done.
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 "chrome/browser/apps/app_browsertest_util.h"
6 #include "chrome/browser/chromeos/drive/drive_integration_service.h"
7 #include "chrome/browser/chromeos/drive/file_system_interface.h"
8 #include "chrome/browser/chromeos/drive/file_system_util.h"
9 #include "chrome/browser/chromeos/drive/test_util.h"
10 #include "chrome/browser/drive/fake_drive_service.h"
11 #include "chrome/browser/extensions/api/file_system/file_system_api.h"
12 #include "content/public/test/test_utils.h"
13 #include "google_apis/drive/test_util.h"
14
15 namespace extensions {
16
17 // This class contains chrome.filesystem API test specific to Chrome OS, namely,
18 // the integrated Google Drive support.
19 class FileSystemApiTestForDrive : public PlatformAppBrowserTest {
20 public:
21 // Sets up fake Drive service for tests (this has to be injected before the
22 // real DriveIntegrationService instance is created.)
23 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
24 PlatformAppBrowserTest::SetUpInProcessBrowserTestFixture();
25
26 ASSERT_TRUE(test_cache_root_.CreateUniqueTempDir());
27
28 create_drive_integration_service_ =
29 base::Bind(&FileSystemApiTestForDrive::CreateDriveIntegrationService,
30 base::Unretained(this));
31 service_factory_for_test_.reset(
32 new drive::DriveIntegrationServiceFactory::ScopedFactoryForTest(
33 &create_drive_integration_service_));
34 }
35
36 // Ensure the fake service's data is fetch in the local file system. This is
37 // necessary because the fetch starts lazily upon the first read operation.
38 virtual void SetUpOnMainThread() OVERRIDE {
39 PlatformAppBrowserTest::SetUpOnMainThread();
40
41 scoped_ptr<drive::ResourceEntry> entry;
42 drive::FileError error = drive::FILE_ERROR_FAILED;
43 integration_service_->file_system()->GetResourceEntry(
44 base::FilePath::FromUTF8Unsafe("drive/root"), // whatever
45 google_apis::test_util::CreateCopyResultCallback(&error, &entry));
46 drive::test_util::RunBlockingPoolTask();
47 ASSERT_EQ(drive::FILE_ERROR_OK, error);
48 }
49
50 virtual void TearDown() OVERRIDE {
51 FileSystemChooseEntryFunction::StopSkippingPickerForTest();
52 PlatformAppBrowserTest::TearDown();
53 };
54
55 private:
56 drive::DriveIntegrationService* CreateDriveIntegrationService(
57 Profile* profile) {
58 fake_drive_service_ = new drive::FakeDriveService;
59 fake_drive_service_->LoadResourceListForWapi(
60 "gdata/empty_feed.json");
61 fake_drive_service_->LoadAccountMetadataForWapi(
62 "gdata/account_metadata.json");
63 fake_drive_service_->LoadAppListForDriveApi("drive/applist.json");
64
65 SetUpTestFileHierarchy();
66
67 integration_service_ = new drive::DriveIntegrationService(
68 profile, NULL, fake_drive_service_, test_cache_root_.path(), NULL);
69 return integration_service_;
70 }
71
72 void SetUpTestFileHierarchy() {
73 const std::string root = fake_drive_service_->GetRootResourceId();
74 ASSERT_TRUE(AddTestFile("open_existing.txt", "Can you see me?", root));
75 }
76
77 bool AddTestFile(const std::string& title,
78 const std::string& data,
79 const std::string& parent_id) {
80 scoped_ptr<google_apis::ResourceEntry> resource_entry;
81 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
82 fake_drive_service_->AddNewFile(
83 "text/plain", data, parent_id, title, false,
84 google_apis::test_util::CreateCopyResultCallback(&error,
85 &resource_entry));
86 content::RunAllPendingInMessageLoop();
87 return error == google_apis::HTTP_CREATED && resource_entry;
88 }
89
90 std::string AddTestDirectory(const std::string& title,
hashimoto 2014/01/15 10:43:15 This function seems unused.
kinaba 2014/01/16 01:36:09 This will be used in the next patch coming soon. R
91 const std::string& parent_id) {
92 scoped_ptr<google_apis::ResourceEntry> resource_entry;
93 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
94 fake_drive_service_->AddNewDirectory(
95 parent_id, title,
96 google_apis::test_util::CreateCopyResultCallback(&error,
97 &resource_entry));
98 content::RunAllPendingInMessageLoop();
99 return error == google_apis::HTTP_CREATED && resource_entry ?
100 resource_entry->resource_id() : "";
101 }
102
103 base::ScopedTempDir test_cache_root_;
104 drive::FakeDriveService* fake_drive_service_;
105 drive::DriveIntegrationService* integration_service_;
hashimoto 2014/01/15 10:43:15 nit: Please initialize these raw pointers in the c
kinaba 2014/01/16 01:36:09 Done.
106 drive::DriveIntegrationServiceFactory::FactoryCallback
107 create_drive_integration_service_;
108 scoped_ptr<drive::DriveIntegrationServiceFactory::ScopedFactoryForTest>
109 service_factory_for_test_;
110 };
111
112 IN_PROC_BROWSER_TEST_F(FileSystemApiTestForDrive,
113 FileSystemApiOpenExistingFileTest) {
114 base::FilePath test_file = drive::util::GetDriveMountPointPath().AppendASCII(
115 "root/open_existing.txt");
116 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
117 &test_file);
118 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_existing"))
119 << message_;
120 }
121
122 IN_PROC_BROWSER_TEST_F(FileSystemApiTestForDrive,
123 FileSystemApiOpenExistingFileWithWriteTest) {
124 base::FilePath test_file = drive::util::GetDriveMountPointPath().AppendASCII(
125 "root/open_existing.txt");
126 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
127 &test_file);
128 ASSERT_TRUE(RunPlatformAppTest(
129 "api_test/file_system/open_existing_with_write")) << message_;
130 }
131
132 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698