| OLD | NEW |
| 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/path_service.h" | 5 #include "base/path_service.h" |
| 6 #include "base/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/background/background_contents_service.h" | 8 #include "chrome/browser/background/background_contents_service.h" |
| 9 #include "chrome/browser/background/background_contents_service_factory.h" | 9 #include "chrome/browser/background/background_contents_service_factory.h" |
| 10 #include "chrome/browser/background/background_mode_manager.h" | 10 #include "chrome/browser/background/background_mode_manager.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 | 149 |
| 150 private: | 150 private: |
| 151 base::FilePath app_dir_; | 151 base::FilePath app_dir_; |
| 152 const Extension* extension_; | 152 const Extension* extension_; |
| 153 }; | 153 }; |
| 154 | 154 |
| 155 // Produces an extensions::ProcessManager::ImpulseCallbackForTesting callback | 155 // Produces an extensions::ProcessManager::ImpulseCallbackForTesting callback |
| 156 // that will match a specified goal and can be waited on. | 156 // that will match a specified goal and can be waited on. |
| 157 class ImpulseCallbackCounter { | 157 class ImpulseCallbackCounter { |
| 158 public: | 158 public: |
| 159 explicit ImpulseCallbackCounter(const std::string& extension_id) | 159 explicit ImpulseCallbackCounter(extensions::ProcessManager* manager, |
| 160 const std::string& extension_id) |
| 160 : observed_(0), | 161 : observed_(0), |
| 161 goal_(0), | 162 goal_(0), |
| 163 manager_(manager), |
| 162 extension_id_(extension_id) { | 164 extension_id_(extension_id) { |
| 163 } | 165 } |
| 164 | 166 |
| 165 extensions::ProcessManager::ImpulseCallbackForTesting | 167 extensions::ProcessManager::ImpulseCallbackForTesting |
| 166 SetGoalAndGetCallback(int goal) { | 168 SetGoalAndGetCallback(int goal) { |
| 167 observed_ = 0; | 169 observed_ = 0; |
| 168 goal_ = goal; | 170 goal_ = goal; |
| 169 message_loop_runner_ = new content::MessageLoopRunner(); | 171 message_loop_runner_ = new content::MessageLoopRunner(); |
| 170 return base::Bind(&ImpulseCallbackCounter::ImpulseCallback, | 172 return base::Bind(&ImpulseCallbackCounter::ImpulseCallback, |
| 171 base::Unretained(this), | 173 base::Unretained(this), |
| 172 message_loop_runner_->QuitClosure(), | 174 message_loop_runner_->QuitClosure(), |
| 173 extension_id_); | 175 extension_id_); |
| 174 } | 176 } |
| 175 | 177 |
| 176 void Wait() { | 178 void Wait() { |
| 177 message_loop_runner_->Run(); | 179 message_loop_runner_->Run(); |
| 178 } | 180 } |
| 179 private: | 181 private: |
| 180 void ImpulseCallback( | 182 void ImpulseCallback( |
| 181 const base::Closure& quit_callback, | 183 const base::Closure& quit_callback, |
| 182 const std::string& extension_id_from_test, | 184 const std::string& extension_id_from_test, |
| 183 const std::string& extension_id_from_manager) { | 185 const std::string& extension_id_from_manager) { |
| 184 if (extension_id_from_test == extension_id_from_manager) { | 186 if (extension_id_from_test == extension_id_from_manager) { |
| 185 if (++observed_ >= goal_) { | 187 if (++observed_ >= goal_) { |
| 188 // Clear callback to free reference to message loop. |
| 189 manager_->SetKeepaliveImpulseCallbackForTesting( |
| 190 extensions::ProcessManager::ImpulseCallbackForTesting()); |
| 191 manager_->SetKeepaliveImpulseDecrementCallbackForTesting( |
| 192 extensions::ProcessManager::ImpulseCallbackForTesting()); |
| 186 quit_callback.Run(); | 193 quit_callback.Run(); |
| 187 } | 194 } |
| 188 } | 195 } |
| 189 } | 196 } |
| 190 | 197 |
| 191 int observed_; | 198 int observed_; |
| 192 int goal_; | 199 int goal_; |
| 200 extensions::ProcessManager* manager_; |
| 193 const std::string extension_id_; | 201 const std::string extension_id_; |
| 194 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | 202 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
| 195 }; | 203 }; |
| 196 | 204 |
| 197 } // namespace | 205 } // namespace |
| 198 | 206 |
| 199 // Disable on Mac only. http://crbug.com/95139 | 207 // Disable on Mac only. http://crbug.com/95139 |
| 200 #if defined(OS_MACOSX) | 208 #if defined(OS_MACOSX) |
| 201 #define MAYBE_Basic DISABLED_Basic | 209 #define MAYBE_Basic DISABLED_Basic |
| 202 #else | 210 #else |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 content::RunAllPendingInMessageLoop(); | 598 content::RunAllPendingInMessageLoop(); |
| 591 ASSERT_TRUE(WaitForBackgroundMode(false)); | 599 ASSERT_TRUE(WaitForBackgroundMode(false)); |
| 592 } | 600 } |
| 593 | 601 |
| 594 // Verify active NaCl embeds cause many keepalive impulses to be sent. | 602 // Verify active NaCl embeds cause many keepalive impulses to be sent. |
| 595 IN_PROC_BROWSER_TEST_F(AppBackgroundPageNaClTest, BackgroundKeepaliveActive) { | 603 IN_PROC_BROWSER_TEST_F(AppBackgroundPageNaClTest, BackgroundKeepaliveActive) { |
| 596 ExtensionTestMessageListener nacl_modules_loaded("nacl_modules_loaded", true); | 604 ExtensionTestMessageListener nacl_modules_loaded("nacl_modules_loaded", true); |
| 597 LaunchTestingApp(); | 605 LaunchTestingApp(); |
| 598 extensions::ProcessManager* manager = | 606 extensions::ProcessManager* manager = |
| 599 extensions::ExtensionSystem::Get(browser()->profile())->process_manager(); | 607 extensions::ExtensionSystem::Get(browser()->profile())->process_manager(); |
| 600 ImpulseCallbackCounter active_impulse_counter(extension()->id()); | 608 ImpulseCallbackCounter active_impulse_counter(manager, extension()->id()); |
| 601 EXPECT_TRUE(nacl_modules_loaded.WaitUntilSatisfied()); | 609 EXPECT_TRUE(nacl_modules_loaded.WaitUntilSatisfied()); |
| 602 | 610 |
| 603 // Target .5 seconds: .5 seconds / 50ms throttle * 2 embeds == 20 impulses. | 611 // Target .5 seconds: .5 seconds / 50ms throttle * 2 embeds == 20 impulses. |
| 604 manager->SetKeepaliveImpulseCallbackForTesting( | 612 manager->SetKeepaliveImpulseCallbackForTesting( |
| 605 active_impulse_counter.SetGoalAndGetCallback(20)); | 613 active_impulse_counter.SetGoalAndGetCallback(20)); |
| 606 active_impulse_counter.Wait(); | 614 active_impulse_counter.Wait(); |
| 607 | |
| 608 // Clear callback to free reference to message loop in ImpulseCallbackCounter. | |
| 609 manager->SetKeepaliveImpulseCallbackForTesting( | |
| 610 extensions::ProcessManager::ImpulseCallbackForTesting()); | |
| 611 } | 615 } |
| 612 | 616 |
| 613 // Verify that nacl modules that go idle will not send keepalive impulses. | 617 // Verify that nacl modules that go idle will not send keepalive impulses. |
| 614 // Disabled on windows due to Win XP failures: | 618 // Disabled on windows due to Win XP failures: |
| 615 // DesktopWindowTreeHostWin::HandleCreate not implemented. crbug.com/331954 | 619 // DesktopWindowTreeHostWin::HandleCreate not implemented. crbug.com/331954 |
| 616 #if defined(OS_WIN) | 620 #if defined(OS_WIN) |
| 617 #define MAYBE_BackgroundKeepaliveIdle DISABLED_BackgroundKeepaliveIdle | 621 #define MAYBE_BackgroundKeepaliveIdle DISABLED_BackgroundKeepaliveIdle |
| 618 #else | 622 #else |
| 619 #define MAYBE_BackgroundKeepaliveIdle BackgroundKeepaliveIdle | 623 #define MAYBE_BackgroundKeepaliveIdle BackgroundKeepaliveIdle |
| 620 #endif | 624 #endif |
| 621 IN_PROC_BROWSER_TEST_F(AppBackgroundPageNaClTest, | 625 IN_PROC_BROWSER_TEST_F(AppBackgroundPageNaClTest, |
| 622 MAYBE_BackgroundKeepaliveIdle) { | 626 MAYBE_BackgroundKeepaliveIdle) { |
| 623 ExtensionTestMessageListener nacl_modules_loaded("nacl_modules_loaded", true); | 627 ExtensionTestMessageListener nacl_modules_loaded("nacl_modules_loaded", true); |
| 624 LaunchTestingApp(); | 628 LaunchTestingApp(); |
| 625 extensions::ProcessManager* manager = | 629 extensions::ProcessManager* manager = |
| 626 extensions::ExtensionSystem::Get(browser()->profile())->process_manager(); | 630 extensions::ExtensionSystem::Get(browser()->profile())->process_manager(); |
| 627 ImpulseCallbackCounter idle_impulse_counter(extension()->id()); | 631 ImpulseCallbackCounter idle_impulse_counter(manager, extension()->id()); |
| 628 EXPECT_TRUE(nacl_modules_loaded.WaitUntilSatisfied()); | 632 EXPECT_TRUE(nacl_modules_loaded.WaitUntilSatisfied()); |
| 629 | 633 |
| 630 manager->SetKeepaliveImpulseDecrementCallbackForTesting( | 634 manager->SetKeepaliveImpulseDecrementCallbackForTesting( |
| 631 idle_impulse_counter.SetGoalAndGetCallback(1)); | 635 idle_impulse_counter.SetGoalAndGetCallback(1)); |
| 632 nacl_modules_loaded.Reply("be idle"); | 636 nacl_modules_loaded.Reply("be idle"); |
| 633 idle_impulse_counter.Wait(); | 637 idle_impulse_counter.Wait(); |
| 634 | |
| 635 // Clear callback to free reference to message loop in ImpulseCallbackCounter. | |
| 636 manager->SetKeepaliveImpulseDecrementCallbackForTesting( | |
| 637 extensions::ProcessManager::ImpulseCallbackForTesting()); | |
| 638 } | 638 } |
| 639 | 639 |
| OLD | NEW |