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

Side by Side Diff: chrome/browser/extensions/app_background_page_apitest.cc

Issue 2762513002: Remove keep-alive impulse IPCs from NaCl modules. (Closed)
Patch Set: Created 3 years, 9 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
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/location.h" 5 #include "base/location.h"
6 #include "base/path_service.h" 6 #include "base/path_service.h"
7 #include "base/single_thread_task_runner.h" 7 #include "base/single_thread_task_runner.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 // Fixture to assist in testing v2 app background pages containing 115 // Fixture to assist in testing v2 app background pages containing
116 // Native Client embeds. 116 // Native Client embeds.
117 class AppBackgroundPageNaClTest : public AppBackgroundPageApiTest { 117 class AppBackgroundPageNaClTest : public AppBackgroundPageApiTest {
118 public: 118 public:
119 AppBackgroundPageNaClTest() 119 AppBackgroundPageNaClTest()
120 : extension_(NULL) {} 120 : extension_(NULL) {}
121 ~AppBackgroundPageNaClTest() override {} 121 ~AppBackgroundPageNaClTest() override {}
122 122
123 void SetUpOnMainThread() override { 123 void SetUpOnMainThread() override {
124 AppBackgroundPageApiTest::SetUpOnMainThread(); 124 AppBackgroundPageApiTest::SetUpOnMainThread();
125 #if !defined(DISABLE_NACL)
126 nacl::NaClProcessHost::SetPpapiKeepAliveThrottleForTesting(50);
127 #endif
128 extensions::ProcessManager::SetEventPageIdleTimeForTesting(1000); 125 extensions::ProcessManager::SetEventPageIdleTimeForTesting(1000);
129 extensions::ProcessManager::SetEventPageSuspendingTimeForTesting(1000); 126 extensions::ProcessManager::SetEventPageSuspendingTimeForTesting(1000);
130 } 127 }
131 128
132 const Extension* extension() { return extension_; } 129 const Extension* extension() { return extension_; }
133 130
134 protected: 131 protected:
135 void LaunchTestingApp() { 132 void LaunchTestingApp() {
136 base::FilePath app_dir; 133 base::FilePath app_dir;
137 PathService::Get(chrome::DIR_GEN_TEST_DATA, &app_dir); 134 PathService::Get(chrome::DIR_GEN_TEST_DATA, &app_dir);
138 app_dir = app_dir.AppendASCII( 135 app_dir = app_dir.AppendASCII(
139 "ppapi/tests/extensions/background_keepalive/newlib"); 136 "ppapi/tests/extensions/background_keepalive/newlib");
140 extension_ = LoadExtension(app_dir); 137 extension_ = LoadExtension(app_dir);
141 ASSERT_TRUE(extension_); 138 ASSERT_TRUE(extension_);
142 } 139 }
143 140
144 private: 141 private:
145 const Extension* extension_; 142 const Extension* extension_;
146 }; 143 };
147 144
148 // Produces an extensions::ProcessManager::ImpulseCallbackForTesting callback
149 // that will match a specified goal and can be waited on.
150 class ImpulseCallbackCounter {
151 public:
152 explicit ImpulseCallbackCounter(extensions::ProcessManager* manager,
153 const std::string& extension_id)
154 : observed_(0),
155 goal_(0),
156 manager_(manager),
157 extension_id_(extension_id) {
158 }
159
160 extensions::ProcessManager::ImpulseCallbackForTesting
161 SetGoalAndGetCallback(int goal) {
162 observed_ = 0;
163 goal_ = goal;
164 message_loop_runner_ = new content::MessageLoopRunner();
165 return base::Bind(&ImpulseCallbackCounter::ImpulseCallback,
166 base::Unretained(this),
167 message_loop_runner_->QuitClosure(),
168 extension_id_);
169 }
170
171 void Wait() {
172 message_loop_runner_->Run();
173 }
174 private:
175 void ImpulseCallback(
176 const base::Closure& quit_callback,
177 const std::string& extension_id_from_test,
178 const std::string& extension_id_from_manager) {
179 if (extension_id_from_test == extension_id_from_manager) {
180 if (++observed_ >= goal_) {
181 // Clear callback to free reference to message loop.
182 manager_->SetKeepaliveImpulseCallbackForTesting(
183 extensions::ProcessManager::ImpulseCallbackForTesting());
184 manager_->SetKeepaliveImpulseDecrementCallbackForTesting(
185 extensions::ProcessManager::ImpulseCallbackForTesting());
186 quit_callback.Run();
187 }
188 }
189 }
190
191 int observed_;
192 int goal_;
193 extensions::ProcessManager* manager_;
194 const std::string extension_id_;
195 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
196 };
197
198 } // namespace 145 } // namespace
199 146
200 // Disable on Mac only. http://crbug.com/95139 147 // Disable on Mac only. http://crbug.com/95139
201 #if defined(OS_MACOSX) 148 #if defined(OS_MACOSX)
202 #define MAYBE_Basic DISABLED_Basic 149 #define MAYBE_Basic DISABLED_Basic
203 #else 150 #else
204 #define MAYBE_Basic Basic 151 #define MAYBE_Basic Basic
205 #endif 152 #endif
206 153
207 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, MAYBE_Basic) { 154 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, MAYBE_Basic) {
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 set_exit_when_last_browser_closes(false); 532 set_exit_when_last_browser_closes(false);
586 CloseBrowserSynchronously(browser()); 533 CloseBrowserSynchronously(browser());
587 534
588 // Post a task to unload the extension - this should cause Chrome to exit 535 // Post a task to unload the extension - this should cause Chrome to exit
589 // cleanly (not crash). 536 // cleanly (not crash).
590 UnloadExtensionViaTask(extension->id()); 537 UnloadExtensionViaTask(extension->id());
591 content::RunAllPendingInMessageLoop(); 538 content::RunAllPendingInMessageLoop();
592 ASSERT_TRUE(WaitForBackgroundMode(false)); 539 ASSERT_TRUE(WaitForBackgroundMode(false));
593 } 540 }
594 541
595 // Verify active NaCl embeds cause many keepalive impulses to be sent. 542 // Verify that active NaCl embeds raise the keepalive count.
596 // Disabled on Windows due to flakiness: http://crbug.com/346278 543 IN_PROC_BROWSER_TEST_F(AppBackgroundPageNaClTest, BackgroundKeepaliveActive) {
597 #if defined(OS_WIN)
598 #define MAYBE_BackgroundKeepaliveActive DISABLED_BackgroundKeepaliveActive
599 #else
600 // Disabling other platforms too since the test started failing
601 // consistently. http://crbug.com/490440
602 #define MAYBE_BackgroundKeepaliveActive DISABLED_BackgroundKeepaliveActive
603 #endif
604 IN_PROC_BROWSER_TEST_F(AppBackgroundPageNaClTest,
605 MAYBE_BackgroundKeepaliveActive) {
606 #if !defined(DISABLE_NACL) 544 #if !defined(DISABLE_NACL)
Devlin 2017/03/21 01:08:15 nit: not directly related to this patch, but can w
Wez 2017/03/21 23:59:22 Is there any reason to even compile the test in DI
607 ExtensionTestMessageListener nacl_modules_loaded("nacl_modules_loaded", true);
608 LaunchTestingApp();
609 extensions::ProcessManager* manager = 545 extensions::ProcessManager* manager =
610 extensions::ProcessManager::Get(browser()->profile()); 546 extensions::ProcessManager::Get(browser()->profile());
611 ImpulseCallbackCounter active_impulse_counter(manager, extension()->id()); 547 ExtensionTestMessageListener ready_listener("ready", true);
612 EXPECT_TRUE(nacl_modules_loaded.WaitUntilSatisfied()); 548 LaunchTestingApp();
549 EXPECT_TRUE(ready_listener.WaitUntilSatisfied());
613 550
614 // Target .5 seconds: .5 seconds / 50ms throttle * 2 embeds == 20 impulses. 551 // Keepalive count set for chrome.test.sendMessage only.
Devlin 2017/03/21 01:08:15 Maybe expand on this: // Since |ready_listener| ha
Wez 2017/03/21 23:59:22 Done.
615 manager->SetKeepaliveImpulseCallbackForTesting( 552 EXPECT_EQ(1, manager->GetLazyKeepaliveCount(extension()));
616 active_impulse_counter.SetGoalAndGetCallback(20)); 553
617 active_impulse_counter.Wait(); 554 ExtensionTestMessageListener created1_listener("created_module:1", true);
555 ready_listener.Reply("create_module");
556 EXPECT_TRUE(created1_listener.WaitUntilSatisfied());
557
558 // Keepalive comes from chrome.test.sendMessage, and one module.
559 EXPECT_EQ(2, manager->GetLazyKeepaliveCount(extension()));
560
561 ExtensionTestMessageListener created2_listener("created_module:2", true);
562 created1_listener.Reply("create_module");
563 EXPECT_TRUE(created2_listener.WaitUntilSatisfied());
564
565 // Keepalive comes from chrome.test.sendMessage, plus two modules.
566 EXPECT_EQ(3, manager->GetLazyKeepaliveCount(extension()));
567
568 // Tear-down both modules.
569 ExtensionTestMessageListener destroyed1_listener("destroyed_module", true);
570 created2_listener.Reply("destroy_module");
571 EXPECT_TRUE(destroyed1_listener.WaitUntilSatisfied());
572 ExtensionTestMessageListener destroyed2_listener("destroyed_module", false);
573 destroyed1_listener.Reply("destroy_module");
574 EXPECT_TRUE(destroyed2_listener.WaitUntilSatisfied());
575
576 // Both modules are gone, and no sendMessage API reply is pending.
577 EXPECT_EQ(0, manager->GetLazyKeepaliveCount(extension()));
618 #endif 578 #endif
619 } 579 }
620 580
621 // Verify that nacl modules that go idle will not send keepalive impulses. 581 // Verify that we can create a NaCl module by adding the <embed> to the
622 // Disabled on windows due to Win XP failures: 582 // background page, without having to e.g. touch emebed.lastError to
623 // DesktopWindowTreeHostWin::HandleCreate not implemented. crbug.com/331954 583 // trigger the module to load.
624 #if defined(OS_WIN) 584 // Disabled due to http://crbug.com/371059.
625 #define MAYBE_BackgroundKeepaliveIdle DISABLED_BackgroundKeepaliveIdle 585 IN_PROC_BROWSER_TEST_F(AppBackgroundPageNaClTest, DISABLED_CreateNaClModule) {
626 #else
627 // ASAN errors appearing: https://crbug.com/332440
628 #define MAYBE_BackgroundKeepaliveIdle DISABLED_BackgroundKeepaliveIdle
629 #endif
630 IN_PROC_BROWSER_TEST_F(AppBackgroundPageNaClTest,
631 MAYBE_BackgroundKeepaliveIdle) {
632 #if !defined(DISABLE_NACL) 586 #if !defined(DISABLE_NACL)
633 ExtensionTestMessageListener nacl_modules_loaded("nacl_modules_loaded", true); 587 ExtensionTestMessageListener ready_listener("ready", true);
634 LaunchTestingApp(); 588 LaunchTestingApp();
635 extensions::ProcessManager* manager = 589 EXPECT_TRUE(ready_listener.WaitUntilSatisfied());
636 extensions::ProcessManager::Get(browser()->profile());
637 ImpulseCallbackCounter idle_impulse_counter(manager, extension()->id());
638 EXPECT_TRUE(nacl_modules_loaded.WaitUntilSatisfied());
639 590
640 manager->SetKeepaliveImpulseDecrementCallbackForTesting( 591 ExtensionTestMessageListener created_listener("created_module:1", false);
641 idle_impulse_counter.SetGoalAndGetCallback(1)); 592 ready_listener.Reply("create_module_without_hack");
642 nacl_modules_loaded.Reply("be idle"); 593 EXPECT_TRUE(created_listener.WaitUntilSatisfied());
643 idle_impulse_counter.Wait();
644 #endif 594 #endif
645 } 595 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/lazy_background_page_apitest.cc » ('j') | extensions/browser/process_manager.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698