| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/test/test_app_window_icon_observer.h" |
| 6 |
| 7 #include "base/run_loop.h" |
| 8 #include "extensions/browser/app_window/app_window.h" |
| 9 #include "ui/aura/client/aura_constants.h" |
| 10 #include "ui/aura/window.h" |
| 11 |
| 12 TestAppWindowIconObserver::TestAppWindowIconObserver( |
| 13 content::BrowserContext* context) |
| 14 : context_(context) { |
| 15 extensions::AppWindowRegistry::Get(context_)->AddObserver(this); |
| 16 } |
| 17 |
| 18 TestAppWindowIconObserver::~TestAppWindowIconObserver() { |
| 19 extensions::AppWindowRegistry::Get(context_)->RemoveObserver(this); |
| 20 for (aura::Window* window : windows_) |
| 21 window->RemoveObserver(this); |
| 22 } |
| 23 |
| 24 void TestAppWindowIconObserver::WaitForIconUpdate() { |
| 25 WaitForIconUpdates(1); |
| 26 } |
| 27 |
| 28 void TestAppWindowIconObserver::WaitForIconUpdates(int updates) { |
| 29 base::RunLoop run_loop; |
| 30 expected_icon_updates_ = updates + icon_updates_; |
| 31 icon_updated_callback_ = run_loop.QuitClosure(); |
| 32 run_loop.Run(); |
| 33 } |
| 34 |
| 35 void TestAppWindowIconObserver::OnAppWindowAdded( |
| 36 extensions::AppWindow* app_window) { |
| 37 aura::Window* window = app_window->GetNativeWindow(); |
| 38 window->AddObserver(this); |
| 39 windows_.push_back(window); |
| 40 } |
| 41 |
| 42 void TestAppWindowIconObserver::OnAppWindowRemoved( |
| 43 extensions::AppWindow* app_window) { |
| 44 aura::Window* window = app_window->GetNativeWindow(); |
| 45 if (window) { |
| 46 windows_.erase(std::find(windows_.begin(), windows_.end(), window)); |
| 47 window->RemoveObserver(this); |
| 48 } |
| 49 } |
| 50 |
| 51 void TestAppWindowIconObserver::OnWindowPropertyChanged(aura::Window* window, |
| 52 const void* key, |
| 53 intptr_t old) { |
| 54 if (key == aura::client::kAppIconKey) { |
| 55 ++icon_updates_; |
| 56 if (icon_updates_ == expected_icon_updates_ && |
| 57 !icon_updated_callback_.is_null()) { |
| 58 base::ResetAndReturn(&icon_updated_callback_).Run(); |
| 59 } |
| 60 } |
| 61 } |
| OLD | NEW |