summaryrefslogtreecommitdiffstats
path: root/chrome/browser/debugger/devtools_sanity_unittest.cc
diff options
context:
space:
mode:
authoryurys@chromium.org <yurys@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-12 08:40:12 +0000
committeryurys@chromium.org <yurys@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-12 08:40:12 +0000
commitd9ddc0db322f5a437c6eb932676308f0ac7b448b (patch)
tree92c1b98aa313c515700146fee6294e7b77cbbfb6 /chrome/browser/debugger/devtools_sanity_unittest.cc
parent83c130ce5753269b00d1ee4891fd27286de068fc (diff)
downloadchromium_src-d9ddc0db322f5a437c6eb932676308f0ac7b448b.zip
chromium_src-d9ddc0db322f5a437c6eb932676308f0ac7b448b.tar.gz
chromium_src-d9ddc0db322f5a437c6eb932676308f0ac7b448b.tar.bz2
DevTools: support shared worker initialization debugger
To be able to debug shared workers initialization, devtools front-end needs to attach very early, before first statement of the worker script is executed. To achieve this on the IO thread we keep a list of shared workers for which devtools front-end was opened and not closed yet. If such worker is destroyed we store its URL and name in the pending workers list and once a new worker is created again we tell it to pause its worker context on start and wait for explicit notification from the devtools client or resume message(in case we learn that the client has already closed on the UI thread). After pause message was sent to the worker being created we put corresponding data to the paused_workers_ list and post reattach task to the UI thread which should result in reattach message to the new worker if the front-end still exists, otherwise when the worker data is removed from the paused_workers_ list we will send resume message and worker will continue to operate as usual. BUG=None TEST=None Review URL: http://codereview.chromium.org/8216008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@105038 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/debugger/devtools_sanity_unittest.cc')
-rw-r--r--chrome/browser/debugger/devtools_sanity_unittest.cc53
1 files changed, 36 insertions, 17 deletions
diff --git a/chrome/browser/debugger/devtools_sanity_unittest.cc b/chrome/browser/debugger/devtools_sanity_unittest.cc
index a03b59d..d0f28f1 100644
--- a/chrome/browser/debugger/devtools_sanity_unittest.cc
+++ b/chrome/browser/debugger/devtools_sanity_unittest.cc
@@ -24,6 +24,8 @@
#include "content/browser/renderer_host/render_view_host.h"
#include "content/browser/tab_contents/tab_contents.h"
#include "content/browser/worker_host/worker_process_host.h"
+#include "content/browser/worker_host/worker_service.h"
+#include "content/browser/worker_host/worker_service_observer.h"
#include "content/common/notification_registrar.h"
#include "content/common/notification_service.h"
#include "net/test/test_server.h"
@@ -267,10 +269,37 @@ class WorkerDevToolsSanityTest : public InProcessBrowserTest {
protected:
struct WorkerData : public base::RefCountedThreadSafe<WorkerData> {
- WorkerData() : worker_process_id(0), worker_route_id(0), valid(false) {}
+ WorkerData() : worker_process_id(0), worker_route_id(0) {}
int worker_process_id;
int worker_route_id;
- bool valid;
+ };
+
+ class WorkerCreationObserver : public WorkerServiceObserver {
+ public:
+ explicit WorkerCreationObserver(WorkerData* worker_data)
+ : worker_data_(worker_data) {
+ }
+
+ private:
+ virtual ~WorkerCreationObserver() {}
+
+ virtual void WorkerCreated (
+ WorkerProcessHost* process,
+ const WorkerProcessHost::WorkerInstance& instance) OVERRIDE {
+ worker_data_->worker_process_id = process->id();
+ worker_data_->worker_route_id = instance.worker_route_id();
+ WorkerService::GetInstance()->RemoveObserver(this);
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+ new MessageLoop::QuitTask);
+ delete this;
+ }
+ virtual void WorkerDestroyed(
+ WorkerProcessHost*,
+ const WorkerProcessHost::WorkerInstance&) OVERRIDE {}
+ virtual void WorkerContextStarted(
+ WorkerProcessHost*,
+ int worker_route_id) OVERRIDE {}
+ scoped_refptr<WorkerData> worker_data_;
};
void RunTest(const char* test_name, const char* test_page) {
@@ -284,8 +313,7 @@ class WorkerDevToolsSanityTest : public InProcessBrowserTest {
}
static void WaitForFirstSharedWorkerOnIOThread(
- scoped_refptr<WorkerData> worker_data,
- int attempt) {
+ scoped_refptr<WorkerData> worker_data) {
BrowserChildProcessHost::Iterator iter(ChildProcessInfo::WORKER_PROCESS);
for (; !iter.Done(); ++iter) {
WorkerProcessHost* worker = static_cast<WorkerProcessHost*>(*iter);
@@ -296,30 +324,21 @@ class WorkerDevToolsSanityTest : public InProcessBrowserTest {
continue;
worker_data->worker_process_id = worker->id();
worker_data->worker_route_id = i->worker_route_id();
- worker_data->valid = true;
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
new MessageLoop::QuitTask);
return;
}
}
- if (attempt > TestTimeouts::action_timeout_ms() /
- TestTimeouts::tiny_timeout_ms())
- FAIL() << "Shared worker not found.";
- MessageLoop::current()->PostDelayedTask(
- FROM_HERE,
- NewRunnableFunction(
- &WaitForFirstSharedWorkerOnIOThread,
- worker_data,
- attempt + 1),
- TestTimeouts::tiny_timeout_ms());
+
+ WorkerService::GetInstance()->AddObserver(
+ new WorkerCreationObserver(worker_data.get()));
}
void OpenDevToolsWindowForFirstSharedWorker() {
scoped_refptr<WorkerData> worker_data(new WorkerData());
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, NewRunnableFunction(
- &WaitForFirstSharedWorkerOnIOThread, worker_data, 1));
+ &WaitForFirstSharedWorkerOnIOThread, worker_data));
ui_test_utils::RunMessageLoop();
- ASSERT_TRUE(worker_data->valid);
Profile* profile = browser()->profile();
window_ = DevToolsWindow::CreateDevToolsWindowForWorker(profile);