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

Side by Side Diff: chrome/browser/chromeos/extensions/file_manager/file_manager_private_apitest.cc

Issue 658013002: Changed api to notify when watched directory is deleted. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/stl_util.h" 5 #include "base/stl_util.h"
6 #include "chrome/browser/chromeos/extensions/file_manager/event_router.h"
6 #include "chrome/browser/chromeos/file_manager/drive_test_util.h" 7 #include "chrome/browser/chromeos/file_manager/drive_test_util.h"
8 #include "chrome/browser/chromeos/file_manager/file_watcher.h"
7 #include "chrome/browser/extensions/extension_apitest.h" 9 #include "chrome/browser/extensions/extension_apitest.h"
10 #include "chrome/test/base/testing_profile.h"
8 #include "chromeos/dbus/cros_disks_client.h" 11 #include "chromeos/dbus/cros_disks_client.h"
9 #include "chromeos/disks/mock_disk_mount_manager.h" 12 #include "chromeos/disks/mock_disk_mount_manager.h"
10 #include "extensions/common/extension.h" 13 #include "extensions/common/extension.h"
11 #include "extensions/common/install_warning.h" 14 #include "extensions/common/install_warning.h"
12 15
13 using ::testing::_; 16 using ::testing::_;
14 using ::testing::ReturnRef; 17 using ::testing::ReturnRef;
15 18
16 using chromeos::disks::DiskMountManager; 19 using chromeos::disks::DiskMountManager;
17 20
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 chromeos::DEVICE_TYPE_OPTICAL_DISC, 104 chromeos::DEVICE_TYPE_OPTICAL_DISC,
102 0, 105 0,
103 true, 106 true,
104 false, 107 false,
105 false, 108 false,
106 true, 109 true,
107 false 110 false
108 } 111 }
109 }; 112 };
110 113
114 struct DispatchDirChangeEve {
mtomasz 2014/10/16 04:02:03 ditto
yawano 2014/10/17 03:57:22 Done.
115 base::FilePath virtual_path;
116 std::vector<std::string> extension_ids;
117 };
118
119 class DispatchDirChangeEveImpl {
120 public:
121 std::vector<DispatchDirChangeEve> events;
122
123 void Callback(const base::FilePath& virtual_path,
124 const drive::FileChange* list,
125 bool got_error,
126 const std::vector<std::string>& extension_ids) {
127 DispatchDirChangeEve dispatch_dir_change_eve;
128 dispatch_dir_change_eve.virtual_path = virtual_path;
129 dispatch_dir_change_eve.extension_ids = extension_ids;
130 events.push_back(dispatch_dir_change_eve);
131 }
132 };
133
134 void AddFileWatchCallback(bool b) { }
135
111 } // namespace 136 } // namespace
112 137
113 class FileManagerPrivateApiTest : public ExtensionApiTest { 138 class FileManagerPrivateApiTest : public ExtensionApiTest {
114 public: 139 public:
115 FileManagerPrivateApiTest() 140 FileManagerPrivateApiTest()
116 : disk_mount_manager_mock_(NULL) { 141 : disk_mount_manager_mock_(NULL) {
117 InitMountPoints(); 142 InitMountPoints();
118 } 143 }
119 144
120 virtual ~FileManagerPrivateApiTest() { 145 virtual ~FileManagerPrivateApiTest() {
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 288
264 IN_PROC_BROWSER_TEST_F(FileManagerPrivateApiTest, Permissions) { 289 IN_PROC_BROWSER_TEST_F(FileManagerPrivateApiTest, Permissions) {
265 EXPECT_TRUE( 290 EXPECT_TRUE(
266 RunExtensionTestIgnoreManifestWarnings("file_browser/permissions")); 291 RunExtensionTestIgnoreManifestWarnings("file_browser/permissions"));
267 const extensions::Extension* extension = GetSingleLoadedExtension(); 292 const extensions::Extension* extension = GetSingleLoadedExtension();
268 ASSERT_TRUE(extension); 293 ASSERT_TRUE(extension);
269 ASSERT_EQ(1u, extension->install_warnings().size()); 294 ASSERT_EQ(1u, extension->install_warnings().size());
270 const extensions::InstallWarning& warning = extension->install_warnings()[0]; 295 const extensions::InstallWarning& warning = extension->install_warnings()[0];
271 EXPECT_EQ("fileManagerPrivate", warning.key); 296 EXPECT_EQ("fileManagerPrivate", warning.key);
272 } 297 }
298
299 IN_PROC_BROWSER_TEST_F(FileManagerPrivateApiTest, OnDirectoryChanged) {
300 TestingProfile profile;
301 file_manager::EventRouter event_router(&profile);
302
303 DispatchDirChangeEveImpl dispatch_dir_change_eve_impl;
304 event_router.SetDispatchDirChangeEveImplForTesting(base::Bind(
305 &DispatchDirChangeEveImpl::Callback,
306 base::Unretained(&dispatch_dir_change_eve_impl)));
307
308 // /a/b/c and /a/d/e are being watched.
309 // In this test case, we assume these pathes does not actually exist in the
310 // machine. (EventRouter does not notify event if the child directory still
311 // exists).
312 event_router.AddFileWatch(base::FilePath("no-existing-fs/root/a/b/c"),
313 base::FilePath("no-existing-fs-virtual/root/a/b/c"),
314 "extension_1",
315 base::Bind(&AddFileWatchCallback));
316
317 event_router.AddFileWatch(base::FilePath("no-existing-fs/root/a/d/e"),
318 base::FilePath("no-existing-fs-hash/root/a/d/e"),
319 "extension_2",
320 base::Bind(&AddFileWatchCallback));
321
322 // When /a/b is deleted (1 and 2 are notified).
323 event_router.OnDirectoryChanged(base::FilePath("no-existing-fs/root/a"));
324 ASSERT_EQ(2lu, dispatch_dir_change_eve_impl.events.size());
325
326 // When /a/b/c is deleted (1 is notified).
327 event_router.OnDirectoryChanged(base::FilePath("no-existing-fs/root/a/b"));
328 ASSERT_EQ(3lu, dispatch_dir_change_eve_impl.events.size());
329
330 // When /z/y is deleted (Not notified)
331 event_router.OnDirectoryChanged(base::FilePath("no-existing-fs/root/z"));
332 ASSERT_EQ(3lu, dispatch_dir_change_eve_impl.events.size());
333
334 event_router.Shutdown();
335 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698