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

Side by Side Diff: apps/app_shim/app_shim_interactive_uitest_mac.mm

Issue 598443002: [Mac] Re-enable AppShimInteractiveTest.Launch. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 6 years, 3 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #import <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 #include <vector> 6 #include <vector>
7 7
8 #include "apps/app_shim/app_shim_handler_mac.h" 8 #include "apps/app_shim/app_shim_handler_mac.h"
9 #include "apps/app_shim/app_shim_host_manager_mac.h" 9 #include "apps/app_shim/app_shim_host_manager_mac.h"
10 #include "apps/app_shim/extension_app_shim_handler_mac.h" 10 #include "apps/app_shim/extension_app_shim_handler_mac.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 base::AutoReset<bool> auto_reset_; 46 base::AutoReset<bool> auto_reset_;
47 47
48 DISALLOW_COPY_AND_ASSIGN(AppShimInteractiveTest); 48 DISALLOW_COPY_AND_ASSIGN(AppShimInteractiveTest);
49 }; 49 };
50 50
51 // Watches for changes to a file. This is designed to be used from the the UI 51 // Watches for changes to a file. This is designed to be used from the the UI
52 // thread. 52 // thread.
53 class WindowedFilePathWatcher 53 class WindowedFilePathWatcher
54 : public base::RefCountedThreadSafe<WindowedFilePathWatcher> { 54 : public base::RefCountedThreadSafe<WindowedFilePathWatcher> {
55 public: 55 public:
56 WindowedFilePathWatcher(const base::FilePath& path) : observed_(false) { 56 WindowedFilePathWatcher(const base::FilePath& path)
57 : path_(path), observed_(false) {
57 content::BrowserThread::PostTask( 58 content::BrowserThread::PostTask(
58 content::BrowserThread::FILE, 59 content::BrowserThread::FILE,
59 FROM_HERE, 60 FROM_HERE,
60 base::Bind(&WindowedFilePathWatcher::Watch, this, path)); 61 base::Bind(&WindowedFilePathWatcher::Watch, this));
61 } 62 }
62 63
63 void Wait() { 64 void Wait() {
64 if (observed_) 65 if (observed_)
65 return; 66 return;
66 67
67 run_loop_.reset(new base::RunLoop); 68 run_loop_.reset(new base::RunLoop);
68 run_loop_->Run(); 69 run_loop_->Run();
69 } 70 }
70 71
71 protected: 72 protected:
72 friend class base::RefCountedThreadSafe<WindowedFilePathWatcher>; 73 friend class base::RefCountedThreadSafe<WindowedFilePathWatcher>;
73 virtual ~WindowedFilePathWatcher() {} 74 virtual ~WindowedFilePathWatcher() {}
74 75
75 void Watch(const base::FilePath& path) { 76 void Watch() {
76 watcher_.Watch( 77 watcher_.reset(new base::FilePathWatcher);
77 path, false, base::Bind(&WindowedFilePathWatcher::Observe, this)); 78 watcher_->Watch(path_.DirName(),
tapted 2014/09/23 07:52:13 optional-nit: I just noticed this returns a bool w
79 false,
80 base::Bind(&WindowedFilePathWatcher::Observe, this));
78 } 81 }
79 82
80 void Observe(const base::FilePath& path, bool error) { 83 void Observe(const base::FilePath& path, bool error) {
81 content::BrowserThread::PostTask( 84 DCHECK(!error);
82 content::BrowserThread::UI, 85 if (base::PathExists(path_)) {
83 FROM_HERE, 86 watcher_.reset();
tapted 2014/09/23 07:52:13 ah - oops I thought Cancel() was on a different cl
84 base::Bind(&WindowedFilePathWatcher::StopRunLoop, this)); 87 content::BrowserThread::PostTask(
88 content::BrowserThread::UI,
89 FROM_HERE,
90 base::Bind(&WindowedFilePathWatcher::StopRunLoop, this));
91 }
85 } 92 }
86 93
87 void StopRunLoop() { 94 void StopRunLoop() {
88 observed_ = true; 95 observed_ = true;
89 if (run_loop_.get()) 96 if (run_loop_.get())
90 run_loop_->Quit(); 97 run_loop_->Quit();
91 } 98 }
92 99
93 private: 100 private:
94 base::FilePathWatcher watcher_; 101 const base::FilePath path_;
102 scoped_ptr<base::FilePathWatcher> watcher_;
95 bool observed_; 103 bool observed_;
96 scoped_ptr<base::RunLoop> run_loop_; 104 scoped_ptr<base::RunLoop> run_loop_;
97 105
98 DISALLOW_COPY_AND_ASSIGN(WindowedFilePathWatcher); 106 DISALLOW_COPY_AND_ASSIGN(WindowedFilePathWatcher);
99 }; 107 };
100 108
101 // Watches for an app shim to connect. 109 // Watches for an app shim to connect.
102 class WindowedAppShimLaunchObserver : public apps::AppShimHandler { 110 class WindowedAppShimLaunchObserver : public apps::AppShimHandler {
103 public: 111 public:
104 WindowedAppShimLaunchObserver(const std::string& app_id) 112 WindowedAppShimLaunchObserver(const std::string& app_id)
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 215
208 runLoop_.reset(new base::RunLoop); 216 runLoop_.reset(new base::RunLoop);
209 runLoop_->Run(); 217 runLoop_->Run();
210 } 218 }
211 219
212 @end 220 @end
213 221
214 namespace apps { 222 namespace apps {
215 223
216 // Shims require static libraries http://crbug.com/386024. 224 // Shims require static libraries http://crbug.com/386024.
217 // This test is flaky on OSX. http://crbug.com/415422 225 #if defined(COMPONENT_BUILD)
218 #if defined(COMPONENT_BUILD) || defined(OS_MACOSX)
219 #define MAYBE_Launch DISABLED_Launch 226 #define MAYBE_Launch DISABLED_Launch
220 #define MAYBE_RebuildShim DISABLED_RebuildShim 227 #define MAYBE_RebuildShim DISABLED_RebuildShim
221 #else 228 #else
222 #define MAYBE_Launch Launch 229 #define MAYBE_Launch Launch
223 #define MAYBE_RebuildShim RebuildShim 230 #define MAYBE_RebuildShim RebuildShim
224 #endif 231 #endif
225 232
226 // Test that launching the shim for an app starts the app, and vice versa. 233 // Test that launching the shim for an app starts the app, and vice versa.
227 // These two cases are combined because the time to run the test is dominated 234 // These two cases are combined because the time to run the test is dominated
228 // by loading the extension and creating the shim. 235 // by loading the extension and creating the shim.
(...skipping 11 matching lines...) Expand all
240 247
241 // Create the internal app shim by simulating an app update. FilePathWatcher 248 // Create the internal app shim by simulating an app update. FilePathWatcher
242 // is used to wait for file operations on the shim to be finished before 249 // is used to wait for file operations on the shim to be finished before
243 // attempting to launch it. Since all of the file operations are done in the 250 // attempting to launch it. Since all of the file operations are done in the
244 // same event on the FILE thread, everything will be done by the time the 251 // same event on the FILE thread, everything will be done by the time the
245 // watcher's callback is executed. 252 // watcher's callback is executed.
246 scoped_refptr<WindowedFilePathWatcher> file_watcher = 253 scoped_refptr<WindowedFilePathWatcher> file_watcher =
247 new WindowedFilePathWatcher(shim_path); 254 new WindowedFilePathWatcher(shim_path);
248 web_app::UpdateAllShortcuts(base::string16(), profile(), app); 255 web_app::UpdateAllShortcuts(base::string16(), profile(), app);
249 file_watcher->Wait(); 256 file_watcher->Wait();
257 ASSERT_TRUE(base::PathExists(shim_path));
250 NSString* bundle_id = GetBundleID(shim_path); 258 NSString* bundle_id = GetBundleID(shim_path);
251 259
252 // Case 1: Launch the shim, it should start the app. 260 // Case 1: Launch the shim, it should start the app.
253 { 261 {
254 ExtensionTestMessageListener launched_listener("Launched", false); 262 ExtensionTestMessageListener launched_listener("Launched", false);
255 CommandLine shim_cmdline(CommandLine::NO_PROGRAM); 263 CommandLine shim_cmdline(CommandLine::NO_PROGRAM);
256 shim_cmdline.AppendSwitch(app_mode::kLaunchedForTest); 264 shim_cmdline.AppendSwitch(app_mode::kLaunchedForTest);
257 ProcessSerialNumber shim_psn; 265 ProcessSerialNumber shim_psn;
258 ASSERT_TRUE(base::mac::OpenApplicationWithPath( 266 ASSERT_TRUE(base::mac::OpenApplicationWithPath(
259 shim_path, shim_cmdline, kLSLaunchDefaults, &shim_psn)); 267 shim_path, shim_cmdline, kLSLaunchDefaults, &shim_psn));
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 // the shim is rebuilt. 398 // the shim is rebuilt.
391 WindowedAppShimLaunchObserver(app->id()).Wait(); 399 WindowedAppShimLaunchObserver(app->id()).Wait();
392 400
393 EXPECT_TRUE(GetFirstAppWindow()); 401 EXPECT_TRUE(GetFirstAppWindow());
394 EXPECT_TRUE(HasAppShimHost(profile(), app->id())); 402 EXPECT_TRUE(HasAppShimHost(profile(), app->id()));
395 } 403 }
396 404
397 #endif // defined(ARCH_CPU_64_BITS) 405 #endif // defined(ARCH_CPU_64_BITS)
398 406
399 } // namespace apps 407 } // namespace apps
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698