OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/browser/chromeos/extensions/file_manager/job_event_router.h" | 5 #include "chrome/browser/chromeos/extensions/file_manager/job_event_router.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/ptr_util.h" | |
12 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
13 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
15 | 14 |
16 namespace file_manager { | 15 namespace file_manager { |
17 namespace { | 16 namespace { |
18 | 17 |
19 class JobEventRouterImpl : public JobEventRouter { | 18 class JobEventRouterImpl : public JobEventRouter { |
20 public: | 19 public: |
21 JobEventRouterImpl() : JobEventRouter(base::TimeDelta::FromMilliseconds(0)) { | 20 JobEventRouterImpl() : JobEventRouter(base::TimeDelta::FromMilliseconds(0)) { |
22 listener_extension_ids_.insert("extension_a"); | 21 listener_extension_ids_.insert("extension_a"); |
23 } | 22 } |
24 std::vector<std::unique_ptr<base::DictionaryValue>> events; | 23 std::vector<linked_ptr<base::DictionaryValue>> events; |
25 | 24 |
26 void SetListenerExtensionIds(std::set<std::string> extension_ids) { | 25 void SetListenerExtensionIds(std::set<std::string> extension_ids) { |
27 listener_extension_ids_ = extension_ids; | 26 listener_extension_ids_ = extension_ids; |
28 } | 27 } |
29 | 28 |
30 protected: | 29 protected: |
31 std::set<std::string> GetFileTransfersUpdateEventListenerExtensionIds() | 30 std::set<std::string> GetFileTransfersUpdateEventListenerExtensionIds() |
32 override { | 31 override { |
33 return listener_extension_ids_; | 32 return listener_extension_ids_; |
34 } | 33 } |
35 | 34 |
36 GURL ConvertDrivePathToFileSystemUrl( | 35 GURL ConvertDrivePathToFileSystemUrl( |
37 const base::FilePath& file_path, | 36 const base::FilePath& file_path, |
38 const std::string& extension_id) override { | 37 const std::string& extension_id) override { |
39 std::string url; | 38 std::string url; |
40 url.append("filesystem:chrome-extension://"); | 39 url.append("filesystem:chrome-extension://"); |
41 url.append(extension_id); | 40 url.append(extension_id); |
42 url.append(file_path.value()); | 41 url.append(file_path.value()); |
43 return GURL(url); | 42 return GURL(url); |
44 } | 43 } |
45 | 44 |
46 void DispatchEventToExtension( | 45 void DispatchEventToExtension( |
47 const std::string& extension_id, | 46 const std::string& extension_id, |
48 extensions::events::HistogramValue histogram_value, | 47 extensions::events::HistogramValue histogram_value, |
49 const std::string& event_name, | 48 const std::string& event_name, |
50 std::unique_ptr<base::ListValue> event_args) override { | 49 std::unique_ptr<base::ListValue> event_args) override { |
51 const base::DictionaryValue* event; | 50 const base::DictionaryValue* event; |
52 event_args->GetDictionary(0, &event); | 51 event_args->GetDictionary(0, &event); |
53 events.push_back(base::WrapUnique(event->DeepCopy())); | 52 events.push_back(make_linked_ptr(event->DeepCopy())); |
54 } | 53 } |
55 | 54 |
56 private: | 55 private: |
57 std::set<std::string> listener_extension_ids_; | 56 std::set<std::string> listener_extension_ids_; |
58 | 57 |
59 DISALLOW_COPY_AND_ASSIGN(JobEventRouterImpl); | 58 DISALLOW_COPY_AND_ASSIGN(JobEventRouterImpl); |
60 }; | 59 }; |
61 | 60 |
62 class JobEventRouterTest : public testing::Test { | 61 class JobEventRouterTest : public testing::Test { |
63 protected: | 62 protected: |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 // Check event for extension_b. | 240 // Check event for extension_b. |
242 EXPECT_EQ("in_progress", GetEventString(1, "transferState")); | 241 EXPECT_EQ("in_progress", GetEventString(1, "transferState")); |
243 EXPECT_EQ(0.0f, GetEventDouble(1, "processed")); | 242 EXPECT_EQ(0.0f, GetEventDouble(1, "processed")); |
244 EXPECT_EQ(100.0f, GetEventDouble(1, "total")); | 243 EXPECT_EQ(100.0f, GetEventDouble(1, "total")); |
245 EXPECT_EQ("filesystem:chrome-extension://extension_b/test/a", | 244 EXPECT_EQ("filesystem:chrome-extension://extension_b/test/a", |
246 GetEventString(1, "fileUrl")); | 245 GetEventString(1, "fileUrl")); |
247 } | 246 } |
248 | 247 |
249 } // namespace | 248 } // namespace |
250 } // namespace file_manager | 249 } // namespace file_manager |
OLD | NEW |