| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 // MediaGalleriesPrivate eject API browser tests. | 5 // MediaGalleriesPrivate eject API browser tests. |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/extensions/extension_apitest.h" | 10 #include "chrome/browser/extensions/extension_apitest.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 | 74 |
| 75 void ExecuteCmdAndCheckReply(content::RenderViewHost* host, | 75 void ExecuteCmdAndCheckReply(content::RenderViewHost* host, |
| 76 const std::string& js_command, | 76 const std::string& js_command, |
| 77 const std::string& ok_message) { | 77 const std::string& ok_message) { |
| 78 ExtensionTestMessageListener listener(ok_message, false); | 78 ExtensionTestMessageListener listener(ok_message, false); |
| 79 host->ExecuteJavascriptInWebFrame(string16(), ASCIIToUTF16(js_command)); | 79 host->ExecuteJavascriptInWebFrame(string16(), ASCIIToUTF16(js_command)); |
| 80 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 80 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
| 81 } | 81 } |
| 82 | 82 |
| 83 void Attach() { | 83 void Attach() { |
| 84 DCHECK(chrome::StorageMonitor::GetInstance()->IsInitialized()); |
| 84 chrome::StorageInfo info(device_id_, ASCIIToUTF16(kDeviceName), kDevicePath, | 85 chrome::StorageInfo info(device_id_, ASCIIToUTF16(kDeviceName), kDevicePath, |
| 85 string16(), string16(), string16(), 0); | 86 string16(), string16(), string16(), 0); |
| 86 chrome::StorageMonitor::GetInstance()->receiver()->ProcessAttach(info); | 87 chrome::StorageMonitor::GetInstance()->receiver()->ProcessAttach(info); |
| 87 content::RunAllPendingInMessageLoop(); | 88 content::RunAllPendingInMessageLoop(); |
| 88 } | 89 } |
| 89 | 90 |
| 90 void Detach() { | 91 void Detach() { |
| 92 DCHECK(chrome::StorageMonitor::GetInstance()->IsInitialized()); |
| 91 chrome::StorageMonitor::GetInstance()->receiver()->ProcessDetach( | 93 chrome::StorageMonitor::GetInstance()->receiver()->ProcessDetach( |
| 92 device_id_); | 94 device_id_); |
| 93 content::RunAllPendingInMessageLoop(); | 95 content::RunAllPendingInMessageLoop(); |
| 94 } | 96 } |
| 95 | 97 |
| 96 static std::string GetDeviceId() { | 98 static std::string GetDeviceId() { |
| 97 return chrome::StorageInfo::MakeDeviceId( | 99 return chrome::StorageInfo::MakeDeviceId( |
| 98 chrome::StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM, kDeviceId); | 100 chrome::StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM, kDeviceId); |
| 99 } | 101 } |
| 100 | 102 |
| 101 protected: | 103 protected: |
| 102 const std::string device_id_; | 104 const std::string device_id_; |
| 103 | 105 |
| 104 private: | 106 private: |
| 105 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesPrivateEjectApiTest); | 107 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesPrivateEjectApiTest); |
| 106 }; | 108 }; |
| 107 | 109 |
| 108 | 110 |
| 109 /////////////////////////////////////////////////////////////////////////////// | 111 /////////////////////////////////////////////////////////////////////////////// |
| 110 // TESTS // | 112 // TESTS // |
| 111 /////////////////////////////////////////////////////////////////////////////// | 113 /////////////////////////////////////////////////////////////////////////////// |
| 112 | 114 |
| 113 IN_PROC_BROWSER_TEST_F(MediaGalleriesPrivateEjectApiTest, EjectTest) { | 115 IN_PROC_BROWSER_TEST_F(MediaGalleriesPrivateEjectApiTest, EjectTest) { |
| 114 scoped_ptr<chrome::test::TestStorageMonitor> monitor( | 116 scoped_ptr<chrome::test::TestStorageMonitor> monitor( |
| 115 chrome::test::TestStorageMonitor::CreateForBrowserTests()); | 117 chrome::test::TestStorageMonitor::CreateForBrowserTests()); |
| 118 monitor->Init(); |
| 119 monitor->MarkInitialized(); |
| 116 | 120 |
| 117 content::RenderViewHost* host = GetHost(); | 121 content::RenderViewHost* host = GetHost(); |
| 118 ExecuteCmdAndCheckReply(host, kAddAttachListenerCmd, kAddAttachListenerOk); | 122 ExecuteCmdAndCheckReply(host, kAddAttachListenerCmd, kAddAttachListenerOk); |
| 119 | 123 |
| 120 // Attach / detach | 124 // Attach / detach |
| 121 const std::string expect_attach_msg = | 125 const std::string expect_attach_msg = |
| 122 base::StringPrintf("%s,%s", kAttachTestOk, kDeviceName); | 126 base::StringPrintf("%s,%s", kAttachTestOk, kDeviceName); |
| 123 ExtensionTestMessageListener attach_finished_listener(expect_attach_msg, | 127 ExtensionTestMessageListener attach_finished_listener(expect_attach_msg, |
| 124 false /* no reply */); | 128 false /* no reply */); |
| 125 Attach(); | 129 Attach(); |
| 126 EXPECT_TRUE(attach_finished_listener.WaitUntilSatisfied()); | 130 EXPECT_TRUE(attach_finished_listener.WaitUntilSatisfied()); |
| 127 | 131 |
| 128 ExecuteCmdAndCheckReply(host, kEjectTestCmd, kEjectListenerOk); | 132 ExecuteCmdAndCheckReply(host, kEjectTestCmd, kEjectListenerOk); |
| 129 EXPECT_EQ(device_id_, monitor->ejected_device()); | 133 EXPECT_EQ(device_id_, monitor->ejected_device()); |
| 130 | 134 |
| 131 Detach(); | 135 Detach(); |
| 132 } | 136 } |
| 133 | 137 |
| 134 IN_PROC_BROWSER_TEST_F(MediaGalleriesPrivateEjectApiTest, EjectBadDeviceTest) { | 138 IN_PROC_BROWSER_TEST_F(MediaGalleriesPrivateEjectApiTest, EjectBadDeviceTest) { |
| 135 scoped_ptr<chrome::test::TestStorageMonitor> monitor( | 139 scoped_ptr<chrome::test::TestStorageMonitor> monitor( |
| 136 chrome::test::TestStorageMonitor::CreateForBrowserTests()); | 140 chrome::test::TestStorageMonitor::CreateForBrowserTests()); |
| 141 monitor->Init(); |
| 142 monitor->MarkInitialized(); |
| 137 | 143 |
| 138 ExecuteCmdAndCheckReply(GetHost(), kEjectFailTestCmd, kEjectFailListenerOk); | 144 ExecuteCmdAndCheckReply(GetHost(), kEjectFailTestCmd, kEjectFailListenerOk); |
| 139 | 145 |
| 140 EXPECT_EQ("", monitor->ejected_device()); | 146 EXPECT_EQ("", monitor->ejected_device()); |
| 141 } | 147 } |
| OLD | NEW |