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/run_loop.h" | |
vandebo (ex-Chrome)
2013/05/31 18:05:03
not needed?
Greg Billock
2013/06/01 01:48:46
removed
On 2013/05/31 18:05:03, vandebo wrote:
| |
8 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
9 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/extensions/extension_apitest.h" | 11 #include "chrome/browser/extensions/extension_apitest.h" |
11 #include "chrome/browser/extensions/extension_process_manager.h" | 12 #include "chrome/browser/extensions/extension_process_manager.h" |
12 #include "chrome/browser/extensions/extension_system.h" | 13 #include "chrome/browser/extensions/extension_system.h" |
13 #include "chrome/browser/extensions/extension_test_message_listener.h" | 14 #include "chrome/browser/extensions/extension_test_message_listener.h" |
14 #include "chrome/browser/media_galleries/media_galleries_test_util.h" | 15 #include "chrome/browser/media_galleries/media_galleries_test_util.h" |
15 #include "chrome/browser/storage_monitor/storage_info.h" | 16 #include "chrome/browser/storage_monitor/storage_info.h" |
16 #include "chrome/browser/storage_monitor/storage_monitor.h" | 17 #include "chrome/browser/storage_monitor/storage_monitor.h" |
17 #include "chrome/browser/storage_monitor/test_storage_monitor.h" | 18 #include "chrome/browser/storage_monitor/test_storage_monitor.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 | 75 |
75 void ExecuteCmdAndCheckReply(content::RenderViewHost* host, | 76 void ExecuteCmdAndCheckReply(content::RenderViewHost* host, |
76 const std::string& js_command, | 77 const std::string& js_command, |
77 const std::string& ok_message) { | 78 const std::string& ok_message) { |
78 ExtensionTestMessageListener listener(ok_message, false); | 79 ExtensionTestMessageListener listener(ok_message, false); |
79 host->ExecuteJavascriptInWebFrame(string16(), ASCIIToUTF16(js_command)); | 80 host->ExecuteJavascriptInWebFrame(string16(), ASCIIToUTF16(js_command)); |
80 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 81 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
81 } | 82 } |
82 | 83 |
83 void Attach() { | 84 void Attach() { |
85 DCHECK(chrome::StorageMonitor::GetInstance()->IsInitialized()); | |
84 chrome::StorageInfo info(device_id_, ASCIIToUTF16(kDeviceName), kDevicePath, | 86 chrome::StorageInfo info(device_id_, ASCIIToUTF16(kDeviceName), kDevicePath, |
85 string16(), string16(), string16(), 0); | 87 string16(), string16(), string16(), 0); |
86 chrome::StorageMonitor::GetInstance()->receiver()->ProcessAttach(info); | 88 chrome::StorageMonitor::GetInstance()->receiver()->ProcessAttach(info); |
87 content::RunAllPendingInMessageLoop(); | 89 content::RunAllPendingInMessageLoop(); |
88 } | 90 } |
89 | 91 |
90 void Detach() { | 92 void Detach() { |
93 DCHECK(chrome::StorageMonitor::GetInstance()->IsInitialized()); | |
91 chrome::StorageMonitor::GetInstance()->receiver()->ProcessDetach( | 94 chrome::StorageMonitor::GetInstance()->receiver()->ProcessDetach( |
92 device_id_); | 95 device_id_); |
93 content::RunAllPendingInMessageLoop(); | 96 content::RunAllPendingInMessageLoop(); |
94 } | 97 } |
95 | 98 |
96 static std::string GetDeviceId() { | 99 static std::string GetDeviceId() { |
97 return chrome::StorageInfo::MakeDeviceId( | 100 return chrome::StorageInfo::MakeDeviceId( |
98 chrome::StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM, kDeviceId); | 101 chrome::StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM, kDeviceId); |
99 } | 102 } |
100 | 103 |
101 protected: | 104 protected: |
102 const std::string device_id_; | 105 const std::string device_id_; |
103 | 106 |
104 private: | 107 private: |
105 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesPrivateEjectApiTest); | 108 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesPrivateEjectApiTest); |
106 }; | 109 }; |
107 | 110 |
108 | 111 |
109 /////////////////////////////////////////////////////////////////////////////// | 112 /////////////////////////////////////////////////////////////////////////////// |
110 // TESTS // | 113 // TESTS // |
111 /////////////////////////////////////////////////////////////////////////////// | 114 /////////////////////////////////////////////////////////////////////////////// |
112 | 115 |
113 IN_PROC_BROWSER_TEST_F(MediaGalleriesPrivateEjectApiTest, EjectTest) { | 116 IN_PROC_BROWSER_TEST_F(MediaGalleriesPrivateEjectApiTest, EjectTest) { |
114 scoped_ptr<chrome::test::TestStorageMonitor> monitor( | 117 scoped_ptr<chrome::test::TestStorageMonitor> monitor( |
115 chrome::test::TestStorageMonitor::CreateForBrowserTests()); | 118 chrome::test::TestStorageMonitor::CreateForBrowserTests()); |
119 monitor->Init(); | |
120 monitor->MarkInitialized(); | |
116 | 121 |
117 content::RenderViewHost* host = GetHost(); | 122 content::RenderViewHost* host = GetHost(); |
118 ExecuteCmdAndCheckReply(host, kAddAttachListenerCmd, kAddAttachListenerOk); | 123 ExecuteCmdAndCheckReply(host, kAddAttachListenerCmd, kAddAttachListenerOk); |
119 | 124 |
120 // Attach / detach | 125 // Attach / detach |
121 const std::string expect_attach_msg = | 126 const std::string expect_attach_msg = |
122 base::StringPrintf("%s,%s", kAttachTestOk, kDeviceName); | 127 base::StringPrintf("%s,%s", kAttachTestOk, kDeviceName); |
123 ExtensionTestMessageListener attach_finished_listener(expect_attach_msg, | 128 ExtensionTestMessageListener attach_finished_listener(expect_attach_msg, |
124 false /* no reply */); | 129 false /* no reply */); |
125 Attach(); | 130 Attach(); |
126 EXPECT_TRUE(attach_finished_listener.WaitUntilSatisfied()); | 131 EXPECT_TRUE(attach_finished_listener.WaitUntilSatisfied()); |
127 | 132 |
128 ExecuteCmdAndCheckReply(host, kEjectTestCmd, kEjectListenerOk); | 133 ExecuteCmdAndCheckReply(host, kEjectTestCmd, kEjectListenerOk); |
129 EXPECT_EQ(device_id_, monitor->ejected_device()); | 134 EXPECT_EQ(device_id_, monitor->ejected_device()); |
130 | 135 |
131 Detach(); | 136 Detach(); |
132 } | 137 } |
133 | 138 |
134 IN_PROC_BROWSER_TEST_F(MediaGalleriesPrivateEjectApiTest, EjectBadDeviceTest) { | 139 IN_PROC_BROWSER_TEST_F(MediaGalleriesPrivateEjectApiTest, EjectBadDeviceTest) { |
135 scoped_ptr<chrome::test::TestStorageMonitor> monitor( | 140 scoped_ptr<chrome::test::TestStorageMonitor> monitor( |
136 chrome::test::TestStorageMonitor::CreateForBrowserTests()); | 141 chrome::test::TestStorageMonitor::CreateForBrowserTests()); |
142 monitor->Init(); | |
143 monitor->MarkInitialized(); | |
137 | 144 |
138 ExecuteCmdAndCheckReply(GetHost(), kEjectFailTestCmd, kEjectFailListenerOk); | 145 ExecuteCmdAndCheckReply(GetHost(), kEjectFailTestCmd, kEjectFailListenerOk); |
139 | 146 |
140 EXPECT_EQ("", monitor->ejected_device()); | 147 EXPECT_EQ("", monitor->ejected_device()); |
141 } | 148 } |
OLD | NEW |