forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure event pages are unloaded when onSuspend calls an API function
Extensions and apps which call API functions with callbacks such as chrome.storage.local.set() and chrome.storage.local.get() in the onSuspend event handler prevents the event page from ever being unloaded. The API function finishes between ExtensionProcessManager::OnSuspendAck() and ExtensionProcessManager::CloseLazyBackgroundPageNow(). The destructor of UIThreadExtensionFunction results in DecrementLazyKeepaliveCount() being called in between these two functions, which increments close_sequence_id. This causes CloseLazyBackgroundPageNow() to drop the delayed close. API functions which finish before OnSuspendAck() will not cause this problem. Fix: DecrementLazyKeepAliveCount() should check the is_closing flag before incrementing close_sequence_id. BUG=296834 TEST=browser_tests (AppEventPageTest*:LazyBackgroundPageApiTest*) See bug for how to reproduce and verify issue. Review URL: https://codereview.chromium.org/24712003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@225906 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
tmdiep@chromium.org
committed
Sep 30, 2013
1 parent
e1632c9
commit 8e7ed72
Showing
14 changed files
with
201 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2013 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/apps/app_browsertest_util.h" | ||
#include "chrome/browser/chrome_notification_types.h" | ||
#include "chrome/browser/extensions/extension_test_message_listener.h" | ||
#include "content/public/browser/notification_service.h" | ||
#include "content/public/test/browser_test.h" | ||
#include "content/public/test/test_utils.h" | ||
|
||
using extensions::Extension; | ||
using extensions::PlatformAppBrowserTest; | ||
|
||
namespace { | ||
|
||
class AppEventPageTest : public PlatformAppBrowserTest { | ||
protected: | ||
void TestUnloadEventPage(const char* app_path) { | ||
// Load and launch the app. | ||
ExtensionTestMessageListener launched_listener("launched", false); | ||
const Extension* extension = LoadAndLaunchPlatformApp(app_path); | ||
ASSERT_TRUE(extension); | ||
ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | ||
|
||
content::WindowedNotificationObserver event_page_suspended( | ||
chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | ||
content::NotificationService::AllSources()); | ||
|
||
// Close the app window. | ||
EXPECT_EQ(1U, GetShellWindowCount()); | ||
apps::ShellWindow* shell_window = GetFirstShellWindow(); | ||
ASSERT_TRUE(shell_window); | ||
CloseShellWindow(shell_window); | ||
|
||
// Verify that the event page is destroyed. | ||
event_page_suspended.Wait(); | ||
} | ||
}; | ||
|
||
} // namespace | ||
|
||
// Tests that an app's event page will eventually be unloaded. The onSuspend | ||
// event handler of this app does not make any API calls. | ||
IN_PROC_BROWSER_TEST_F(AppEventPageTest, OnSuspendNoApiUse) { | ||
TestUnloadEventPage("event_page/suspend_simple"); | ||
} | ||
|
||
// Tests that an app's event page will eventually be unloaded. The onSuspend | ||
// event handler of this app calls a chrome.storage API function. | ||
// See: http://crbug.com/296834 | ||
IN_PROC_BROWSER_TEST_F(AppEventPageTest, OnSuspendUseStorageApi) { | ||
TestUnloadEventPage("event_page/suspend_storage_api"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
chrome/test/data/extensions/api_test/lazy_background_page/on_suspend/background.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright 2013 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
chrome.runtime.onSuspend.addListener(function() { | ||
var now = new Date(); | ||
chrome.storage.local.set({"last_save": now.toLocaleString()}, function() { | ||
console.log("Finished writing last_save: " + now.toLocaleString()); | ||
}); | ||
}); |
10 changes: 10 additions & 0 deletions
10
chrome/test/data/extensions/api_test/lazy_background_page/on_suspend/manifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "Lazy BG onSuspend Test", | ||
"version": "1.0", | ||
"manifest_version": 2, | ||
"permissions": ["storage"], | ||
"background": { | ||
"scripts": ["background.js"], | ||
"persistent": false | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
chrome/test/data/extensions/platform_apps/event_page/suspend_simple/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- | ||
* Copyright 2013 The Chromium Authors. All rights reserved. | ||
* Use of this source code is governed by a BSD-style license that can be | ||
* found in the LICENSE file. | ||
--> | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
</head> | ||
<body> | ||
<script src="index.js"></script> | ||
</body> | ||
</html> |
7 changes: 7 additions & 0 deletions
7
chrome/test/data/extensions/platform_apps/event_page/suspend_simple/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Copyright 2013 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
onload = function() { | ||
chrome.test.sendMessage('launched'); | ||
}; |
25 changes: 25 additions & 0 deletions
25
chrome/test/data/extensions/platform_apps/event_page/suspend_simple/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2013 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
chrome.app.runtime.onLaunched.addListener(function() { | ||
|
||
var screenWidth = screen.availWidth; | ||
var screenHeight = screen.availHeight; | ||
var width = 500; | ||
var height = 300; | ||
|
||
chrome.app.window.create('index.html', { | ||
bounds: { | ||
width: width, | ||
height: height, | ||
left: Math.round((screenWidth-width)/2), | ||
top: Math.round((screenHeight-height)/2) | ||
} | ||
}); | ||
}); | ||
|
||
chrome.runtime.onSuspend.addListener(function() { | ||
var now = new Date(); | ||
console.log("The current time is: " + now.toLocaleString()); | ||
}); |
10 changes: 10 additions & 0 deletions
10
chrome/test/data/extensions/platform_apps/event_page/suspend_simple/manifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "Event Page Test - Simple", | ||
"version": "1.0", | ||
"manifest_version": 2, | ||
"app": { | ||
"background": { | ||
"scripts": ["main.js"] | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
chrome/test/data/extensions/platform_apps/event_page/suspend_storage_api/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- | ||
* Copyright 2013 The Chromium Authors. All rights reserved. | ||
* Use of this source code is governed by a BSD-style license that can be | ||
* found in the LICENSE file. | ||
--> | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
</head> | ||
<body> | ||
<script src="index.js"></script> | ||
</body> | ||
</html> |
7 changes: 7 additions & 0 deletions
7
chrome/test/data/extensions/platform_apps/event_page/suspend_storage_api/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Copyright 2013 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
onload = function() { | ||
chrome.test.sendMessage('launched'); | ||
}; |
27 changes: 27 additions & 0 deletions
27
chrome/test/data/extensions/platform_apps/event_page/suspend_storage_api/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2013 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
chrome.app.runtime.onLaunched.addListener(function() { | ||
|
||
var screenWidth = screen.availWidth; | ||
var screenHeight = screen.availHeight; | ||
var width = 500; | ||
var height = 300; | ||
|
||
chrome.app.window.create('index.html', { | ||
bounds: { | ||
width: width, | ||
height: height, | ||
left: Math.round((screenWidth-width)/2), | ||
top: Math.round((screenHeight-height)/2) | ||
} | ||
}); | ||
}); | ||
|
||
chrome.runtime.onSuspend.addListener(function() { | ||
var now = new Date(); | ||
chrome.storage.local.set({"last_save": now.toLocaleString()}, function() { | ||
console.log("Finished writing last_save: " + now.toLocaleString()); | ||
}); | ||
}); |
11 changes: 11 additions & 0 deletions
11
chrome/test/data/extensions/platform_apps/event_page/suspend_storage_api/manifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "Event Page Test - Storage API", | ||
"version": "1.0", | ||
"manifest_version": 2, | ||
"permissions": ["storage"], | ||
"app": { | ||
"background": { | ||
"scripts": ["main.js"] | ||
} | ||
} | ||
} |