| OLD | NEW |
| 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/strings/stringprintf.h" | 5 #include "base/strings/stringprintf.h" |
| 6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
| 7 #include "chrome/browser/extensions/api/media_galleries_private/media_galleries_
private_api.h" | 7 #include "chrome/browser/extensions/api/media_galleries_private/media_galleries_
private_api.h" |
| 8 #include "chrome/browser/extensions/extension_apitest.h" | 8 #include "chrome/browser/extensions/extension_apitest.h" |
| 9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
| 10 #include "chrome/browser/extensions/extension_system.h" | 10 #include "chrome/browser/extensions/extension_system.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 | 53 |
| 54 } // namespace | 54 } // namespace |
| 55 | 55 |
| 56 class MediaGalleriesPrivateApiTest : public ExtensionApiTest { | 56 class MediaGalleriesPrivateApiTest : public ExtensionApiTest { |
| 57 public: | 57 public: |
| 58 MediaGalleriesPrivateApiTest() {} | 58 MediaGalleriesPrivateApiTest() {} |
| 59 virtual ~MediaGalleriesPrivateApiTest() {} | 59 virtual ~MediaGalleriesPrivateApiTest() {} |
| 60 | 60 |
| 61 // ExtensionApiTest overrides. | 61 // ExtensionApiTest overrides. |
| 62 virtual void SetUp() OVERRIDE { | 62 virtual void SetUp() OVERRIDE { |
| 63 device_id_ = chrome::StorageInfo::MakeDeviceId( | 63 device_id_ = StorageInfo::MakeDeviceId( |
| 64 chrome::StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM, kDeviceId); | 64 StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM, kDeviceId); |
| 65 ExtensionApiTest::SetUp(); | 65 ExtensionApiTest::SetUp(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 protected: | 68 protected: |
| 69 // ExtensionApiTest overrides. | 69 // ExtensionApiTest overrides. |
| 70 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 70 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 71 ExtensionApiTest::SetUpCommandLine(command_line); | 71 ExtensionApiTest::SetUpCommandLine(command_line); |
| 72 command_line->AppendSwitchASCII(switches::kWhitelistedExtensionID, | 72 command_line->AppendSwitchASCII(switches::kWhitelistedExtensionID, |
| 73 kTestExtensionId); | 73 kTestExtensionId); |
| 74 } | 74 } |
| 75 | 75 |
| 76 void ChangeListener(content::RenderViewHost* host, | 76 void ChangeListener(content::RenderViewHost* host, |
| 77 const std::string& js_command, | 77 const std::string& js_command, |
| 78 const std::string& ok_message) { | 78 const std::string& ok_message) { |
| 79 ExtensionTestMessageListener listener(ok_message, false /* no reply */); | 79 ExtensionTestMessageListener listener(ok_message, false /* no reply */); |
| 80 host->ExecuteJavascriptInWebFrame(string16(), ASCIIToUTF16(js_command)); | 80 host->ExecuteJavascriptInWebFrame(string16(), ASCIIToUTF16(js_command)); |
| 81 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 81 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
| 82 } | 82 } |
| 83 | 83 |
| 84 void AttachDetach() { | 84 void AttachDetach() { |
| 85 Attach(); | 85 Attach(); |
| 86 Detach(); | 86 Detach(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 void Attach() { | 89 void Attach() { |
| 90 DCHECK(chrome::StorageMonitor::GetInstance()->IsInitialized()); | 90 DCHECK(StorageMonitor::GetInstance()->IsInitialized()); |
| 91 chrome::StorageInfo info(device_id_, ASCIIToUTF16(kDeviceName), kDevicePath, | 91 StorageInfo info(device_id_, ASCIIToUTF16(kDeviceName), kDevicePath, |
| 92 string16(), string16(), string16(), 0); | 92 string16(), string16(), string16(), 0); |
| 93 chrome::StorageMonitor::GetInstance()->receiver()->ProcessAttach(info); | 93 StorageMonitor::GetInstance()->receiver()->ProcessAttach(info); |
| 94 content::RunAllPendingInMessageLoop(); | 94 content::RunAllPendingInMessageLoop(); |
| 95 } | 95 } |
| 96 | 96 |
| 97 void Detach() { | 97 void Detach() { |
| 98 DCHECK(chrome::StorageMonitor::GetInstance()->IsInitialized()); | 98 DCHECK(StorageMonitor::GetInstance()->IsInitialized()); |
| 99 chrome::StorageMonitor::GetInstance()->receiver()->ProcessDetach( | 99 StorageMonitor::GetInstance()->receiver()->ProcessDetach(device_id_); |
| 100 device_id_); | |
| 101 content::RunAllPendingInMessageLoop(); | 100 content::RunAllPendingInMessageLoop(); |
| 102 } | 101 } |
| 103 | 102 |
| 104 private: | 103 private: |
| 105 std::string device_id_; | 104 std::string device_id_; |
| 106 | 105 |
| 107 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesPrivateApiTest); | 106 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesPrivateApiTest); |
| 108 }; | 107 }; |
| 109 | 108 |
| 110 IN_PROC_BROWSER_TEST_F(MediaGalleriesPrivateApiTest, DeviceAttachDetachEvents) { | 109 IN_PROC_BROWSER_TEST_F(MediaGalleriesPrivateApiTest, DeviceAttachDetachEvents) { |
| 111 // Setup. | 110 // Setup. |
| 112 chrome::test::TestStorageMonitor::SyncInitialize(); | 111 TestStorageMonitor::SyncInitialize(); |
| 113 const extensions::Extension* extension = | 112 const extensions::Extension* extension = |
| 114 LoadExtension(test_data_dir_.AppendASCII(kTestExtensionPath)); | 113 LoadExtension(test_data_dir_.AppendASCII(kTestExtensionPath)); |
| 115 ASSERT_TRUE(extension); | 114 ASSERT_TRUE(extension); |
| 116 | 115 |
| 117 content::RenderViewHost* host = | 116 content::RenderViewHost* host = |
| 118 extensions::ExtensionSystem::Get(browser()->profile())-> | 117 extensions::ExtensionSystem::Get(browser()->profile())-> |
| 119 process_manager()->GetBackgroundHostForExtension(extension->id())-> | 118 process_manager()->GetBackgroundHostForExtension(extension->id())-> |
| 120 render_view_host(); | 119 render_view_host(); |
| 121 ASSERT_TRUE(host); | 120 ASSERT_TRUE(host); |
| 122 | 121 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 Attach(); | 175 Attach(); |
| 177 EXPECT_TRUE(attach_finished_listener.WaitUntilSatisfied()); | 176 EXPECT_TRUE(attach_finished_listener.WaitUntilSatisfied()); |
| 178 Detach(); | 177 Detach(); |
| 179 EXPECT_TRUE(detach_finished_listener.WaitUntilSatisfied()); | 178 EXPECT_TRUE(detach_finished_listener.WaitUntilSatisfied()); |
| 180 | 179 |
| 181 Attach(); | 180 Attach(); |
| 182 EXPECT_TRUE(attach_finished_listener.WaitUntilSatisfied()); | 181 EXPECT_TRUE(attach_finished_listener.WaitUntilSatisfied()); |
| 183 Detach(); | 182 Detach(); |
| 184 EXPECT_TRUE(detach_finished_listener.WaitUntilSatisfied()); | 183 EXPECT_TRUE(detach_finished_listener.WaitUntilSatisfied()); |
| 185 } | 184 } |
| OLD | NEW |