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

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

Issue 1016473002: Make LoadMonitoringExtensionHostQueue remove itself as an ExtensionHost observer at the correct tim… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Another rename Created 5 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/base64.h" 5 #include "base/base64.h"
6 #include "base/files/file_path.h" 6 #include "base/files/file_path.h"
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "net/url_request/url_request_context_getter.h" 42 #include "net/url_request/url_request_context_getter.h"
43 #include "url/gurl.h" 43 #include "url/gurl.h"
44 44
45 namespace extensions { 45 namespace extensions {
46 namespace { 46 namespace {
47 47
48 class MessageSender : public content::NotificationObserver { 48 class MessageSender : public content::NotificationObserver {
49 public: 49 public:
50 MessageSender() { 50 MessageSender() {
51 registrar_.Add(this, 51 registrar_.Add(this,
52 extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, 52 extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_FIRST_LOAD,
53 content::NotificationService::AllSources()); 53 content::NotificationService::AllSources());
54 } 54 }
55 55
56 private: 56 private:
57 static scoped_ptr<base::ListValue> BuildEventArguments( 57 static scoped_ptr<base::ListValue> BuildEventArguments(
58 const bool last_message, 58 const bool last_message,
59 const std::string& data) { 59 const std::string& data) {
60 base::DictionaryValue* event = new base::DictionaryValue(); 60 base::DictionaryValue* event = new base::DictionaryValue();
61 event->SetBoolean("lastMessage", last_message); 61 event->SetBoolean("lastMessage", last_message);
62 event->SetString("data", data); 62 event->SetString("data", data);
63 scoped_ptr<base::ListValue> arguments(new base::ListValue()); 63 scoped_ptr<base::ListValue> arguments(new base::ListValue());
64 arguments->Append(event); 64 arguments->Append(event);
65 return arguments.Pass(); 65 return arguments.Pass();
66 } 66 }
67 67
68 static scoped_ptr<Event> BuildEvent(scoped_ptr<base::ListValue> event_args, 68 static scoped_ptr<Event> BuildEvent(scoped_ptr<base::ListValue> event_args,
69 Profile* profile, 69 Profile* profile,
70 GURL event_url) { 70 GURL event_url) {
71 scoped_ptr<Event> event(new Event("test.onMessage", event_args.Pass())); 71 scoped_ptr<Event> event(new Event("test.onMessage", event_args.Pass()));
72 event->restrict_to_browser_context = profile; 72 event->restrict_to_browser_context = profile;
73 event->event_url = event_url; 73 event->event_url = event_url;
74 return event.Pass(); 74 return event.Pass();
75 } 75 }
76 76
77 void Observe(int type, 77 void Observe(int type,
78 const content::NotificationSource& source, 78 const content::NotificationSource& source,
79 const content::NotificationDetails& details) override { 79 const content::NotificationDetails& details) override {
80 DCHECK_EQ(extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, type); 80 DCHECK_EQ(extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_FIRST_LOAD,
81 type);
81 EventRouter* event_router = 82 EventRouter* event_router =
82 EventRouter::Get(content::Source<Profile>(source).ptr()); 83 EventRouter::Get(content::Source<Profile>(source).ptr());
83 84
84 // Sends four messages to the extension. All but the third message sent 85 // Sends four messages to the extension. All but the third message sent
85 // from the origin http://b.com/ are supposed to arrive. 86 // from the origin http://b.com/ are supposed to arrive.
86 event_router->BroadcastEvent(BuildEvent( 87 event_router->BroadcastEvent(BuildEvent(
87 BuildEventArguments(false, "no restriction"), 88 BuildEventArguments(false, "no restriction"),
88 content::Source<Profile>(source).ptr(), 89 content::Source<Profile>(source).ptr(),
89 GURL())); 90 GURL()));
90 event_router->BroadcastEvent(BuildEvent( 91 event_router->BroadcastEvent(BuildEvent(
(...skipping 1095 matching lines...) Expand 10 before | Expand all | Expand 10 after
1186 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); 1187 ui_test_utils::NavigateToURL(browser(), chromium_org_url());
1187 EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR, 1188 EXPECT_EQ(COULD_NOT_ESTABLISH_CONNECTION_ERROR,
1188 CanConnectAndSendMessagesToMainFrame(invalid.get())); 1189 CanConnectAndSendMessagesToMainFrame(invalid.get()));
1189 } 1190 }
1190 1191
1191 #endif // !defined(OS_WIN) - http://crbug.com/350517. 1192 #endif // !defined(OS_WIN) - http://crbug.com/350517.
1192 1193
1193 } // namespace 1194 } // namespace
1194 1195
1195 }; // namespace extensions 1196 }; // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698