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

Side by Side Diff: chrome/browser/extensions/api/media_galleries_private/media_galleries_private_apitest.cc

Issue 11299326: Revert 170660 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years 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 | Annotate | Revision Log
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/stringprintf.h" 5 #include "base/stringprintf.h"
6 #include "base/system_monitor/system_monitor.h" 6 #include "base/system_monitor/system_monitor.h"
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/extensions/api/media_galleries_private/media_galleries_ private_api.h" 8 #include "chrome/browser/extensions/api/media_galleries_private/media_galleries_ private_api.h"
9 #include "chrome/browser/extensions/extension_apitest.h" 9 #include "chrome/browser/extensions/extension_apitest.h"
10 #include "chrome/browser/extensions/extension_service.h" 10 #include "chrome/browser/extensions/extension_service.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 } 73 }
74 74
75 void ChangeListener(content::RenderViewHost* host, 75 void ChangeListener(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 /* no reply */); 78 ExtensionTestMessageListener listener(ok_message, false /* no reply */);
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(bool listening) { 83 void AttachDetach() {
84 const std::string expect_attach_msg = 84 Attach();
85 base::StringPrintf("%s,%s", kAttachTestOk, kDeviceName); 85 Detach();
86 ExtensionTestMessageListener attach_finished_listener( 86 }
87 expect_attach_msg, 87
88 false /* no reply */); 88 void Attach() {
89 base::SystemMonitor::Get()->ProcessRemovableStorageAttached( 89 base::SystemMonitor::Get()->ProcessRemovableStorageAttached(
90 device_id_, ASCIIToUTF16(kDeviceName), kDevicePath); 90 device_id_, ASCIIToUTF16(kDeviceName), kDevicePath);
91 WaitForDeviceEvents(); 91 WaitForDeviceEvents();
92 if (listening)
93 EXPECT_TRUE(attach_finished_listener.WaitUntilSatisfied());
94 } 92 }
95 93
96 void Detach(bool listening) { 94 void Detach() {
97 ExtensionTestMessageListener detach_finished_listener(
98 kDetachTestOk,
99 false /* no reply */);
100 base::SystemMonitor::Get()->ProcessRemovableStorageDetached(device_id_); 95 base::SystemMonitor::Get()->ProcessRemovableStorageDetached(device_id_);
101 WaitForDeviceEvents(); 96 WaitForDeviceEvents();
102 if (listening)
103 EXPECT_TRUE(detach_finished_listener.WaitUntilSatisfied());
104 } 97 }
105 98
106 private: 99 private:
107 void WaitForDeviceEvents() { 100 void WaitForDeviceEvents() {
108 content::RunAllPendingInMessageLoop(); 101 content::RunAllPendingInMessageLoop();
109 } 102 }
110 103
111 std::string device_id_; 104 std::string device_id_;
112 105
113 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesPrivateApiTest); 106 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesPrivateApiTest);
114 }; 107 };
115 108
116 IN_PROC_BROWSER_TEST_F(MediaGalleriesPrivateApiTest, DeviceAttachDetachEvents) { 109 IN_PROC_BROWSER_TEST_F(MediaGalleriesPrivateApiTest, DeviceAttachDetachEvents) {
117 // Setup. 110 // Setup.
118 const extensions::Extension* extension = 111 const extensions::Extension* extension =
119 LoadExtension(test_data_dir_.AppendASCII(kTestExtensionPath)); 112 LoadExtension(test_data_dir_.AppendASCII(kTestExtensionPath));
120 ASSERT_TRUE(extension); 113 ASSERT_TRUE(extension);
121 114
122 content::RenderViewHost* host = 115 content::RenderViewHost* host =
123 extensions::ExtensionSystem::Get(browser()->profile())-> 116 extensions::ExtensionSystem::Get(browser()->profile())->
124 process_manager()->GetBackgroundHostForExtension(extension->id())-> 117 process_manager()->GetBackgroundHostForExtension(extension->id())->
125 render_view_host(); 118 render_view_host();
126 ASSERT_TRUE(host); 119 ASSERT_TRUE(host);
127 120
128 // No listeners, attach and detach a couple times. 121 // No listeners, attach and detach a couple times.
129 Attach(false); 122 AttachDetach();
130 Detach(false); 123 AttachDetach();
131 Attach(false);
132 Detach(false);
133 124
134 // Add attach listener. 125 // Add attach listener.
135 ChangeListener(host, kAddAttachListenerCmd, kAddAttachListenerOk); 126 ChangeListener(host, kAddAttachListenerCmd, kAddAttachListenerOk);
136 127
137 // Attach / detach 128 // Attach / detach
138 Attach(true); 129 const std::string expect_attach_msg =
139 Detach(false); 130 base::StringPrintf("%s,%s", kAttachTestOk, kDeviceName);
131 ExtensionTestMessageListener attach_finished_listener(expect_attach_msg,
132 false /* no reply */);
133 Attach();
134 EXPECT_TRUE(attach_finished_listener.WaitUntilSatisfied());
135 Detach();
140 136
141 // Attach / detach 137 // Attach / detach
142 Attach(true); 138 Attach();
143 Detach(false); 139 EXPECT_TRUE(attach_finished_listener.WaitUntilSatisfied());
140 // Detach
141 Detach();
144 142
145 // Remove attach listener. 143 // Remove attach listener.
146 ChangeListener(host, kRemoveAttachListenerCmd, kRemoveAttachListenerOk); 144 ChangeListener(host, kRemoveAttachListenerCmd, kRemoveAttachListenerOk);
147 145
148 // No listeners, attach and detach a couple times. 146 // No listeners, attach and detach a couple times.
149 Attach(false); 147 AttachDetach();
150 Detach(false); 148 AttachDetach();
151 Attach(false);
152 Detach(false);
153 149
154 // Add detach listener. 150 // Add detach listener.
155 ChangeListener(host, kAddDummyDetachListenerCmd, kAddDummyDetachListenerOk); 151 ChangeListener(host, kAddDummyDetachListenerCmd, kAddDummyDetachListenerOk);
156 152
157 // Attach / detach 153 // Attach / detach
158 Attach(false); 154 Attach();
159 Detach(true); 155
156 ExtensionTestMessageListener detach_finished_listener(kDetachTestOk,
157 false /* no reply */);
158 Detach();
159 EXPECT_TRUE(detach_finished_listener.WaitUntilSatisfied());
160 160
161 // Attach / detach 161 // Attach / detach
162 Attach(false); 162 Attach();
163 Detach(true); 163 Detach();
164 EXPECT_TRUE(detach_finished_listener.WaitUntilSatisfied());
164 165
165 // Switch ok dummy detach listener for the regular one. 166 // Switch ok dummy detach listener for the regular one.
166 ChangeListener(host, kRemoveDummyDetachListenerCmd, 167 ChangeListener(host, kRemoveDummyDetachListenerCmd,
167 kRemoveDummyDetachListenerOk); 168 kRemoveDummyDetachListenerOk);
168 ChangeListener(host, kAddDetachListenerCmd, kAddDetachListenerOk); 169 ChangeListener(host, kAddDetachListenerCmd, kAddDetachListenerOk);
169 170
170 // Add attach listener. 171 // Add attach listener.
171 ChangeListener(host, kAddAttachListenerCmd, kAddAttachListenerOk); 172 ChangeListener(host, kAddAttachListenerCmd, kAddAttachListenerOk);
172 173
173 Attach(true); 174 Attach();
174 Detach(true); 175 EXPECT_TRUE(attach_finished_listener.WaitUntilSatisfied());
176 Detach();
177 EXPECT_TRUE(detach_finished_listener.WaitUntilSatisfied());
175 178
176 Attach(true); 179 Attach();
177 Detach(true); 180 EXPECT_TRUE(attach_finished_listener.WaitUntilSatisfied());
178 CloseShellWindowsAndWaitForAppToExit(); 181 Detach();
182 EXPECT_TRUE(detach_finished_listener.WaitUntilSatisfied());
179 } 183 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698