diff options
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/common/child_process_info.h | 232 | ||||
-rw-r--r-- | chrome/common/extensions/user_script_unittest.cc | 202 | ||||
-rw-r--r-- | chrome/common/gfx/DEPS | 6 | ||||
-rw-r--r-- | chrome/common/ipc_test_sink.cc | 102 | ||||
-rw-r--r-- | chrome/common/ipc_test_sink.h | 168 | ||||
-rw-r--r-- | chrome/common/notification_observer.h | 46 |
6 files changed, 378 insertions, 378 deletions
diff --git a/chrome/common/child_process_info.h b/chrome/common/child_process_info.h index d95eac4..cb34238 100644 --- a/chrome/common/child_process_info.h +++ b/chrome/common/child_process_info.h @@ -1,116 +1,116 @@ -// Copyright (c) 2009 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.
-
-#ifndef CHROME_COMMON_CHILD_PROCESS_INFO_H_
-#define CHROME_COMMON_CHILD_PROCESS_INFO_H_
-
-#include <list>
-#include <string>
-
-#include "base/basictypes.h"
-#include "base/process.h"
-
-class ChildProcessInfo;
-
-// Holds information about a child process. Plugins/workers and other child
-// processes that live on the IO thread derive from this.
-class ChildProcessInfo {
- public:
- enum ProcessType {
- BROWSER_PROCESS,
- RENDER_PROCESS,
- PLUGIN_PROCESS,
- WORKER_PROCESS,
- UNKNOWN_PROCESS,
- };
-
- // Returns the type of the process.
- ProcessType type() const { return type_; }
-
- // Returns the name of the process. i.e. for plugins it might be Flash, while
- // for workers it might be the domain that it's from.
- std::wstring name() const { return name_; }
-
- // Getter to the process.
- base::Process& process() { return process_; }
-
- // Returns an English name of the process type, should only be used for non
- // user-visible strings, or debugging pages like about:memory.
- static std::wstring GetTypeNameInEnglish(ProcessType type);
-
- // Returns a localized title for the child process. For example, a plugin
- // process would be "Plug-in: Flash" when name is "Flash".
- std::wstring GetLocalizedTitle() const;
-
- ChildProcessInfo(const ChildProcessInfo& original) {
- type_ = original.type_;
- name_ = original.name_;
- process_ = original.process_;
- }
-
- ChildProcessInfo& operator=(const ChildProcessInfo& original) {
- if (&original != this) {
- type_ = original.type_;
- name_ = original.name_;
- process_ = original.process_;
- }
- return *this;
- }
-
- ~ChildProcessInfo();
-
- // We define the < operator so that the ChildProcessInfo can be used as a key
- // in a std::map.
- bool operator <(const ChildProcessInfo& rhs) const {
- if (process_.handle() != rhs.process_.handle())
- return process_ .handle() < rhs.process_.handle();
- return name_ < rhs.name_;
- }
-
- bool operator ==(const ChildProcessInfo& rhs) const {
- return (process_.handle() == rhs.process_.handle()) && (name_ == rhs.name_);
- }
-
- // The Iterator class allows iteration through either all child processes, or
- // ones of a specific type, depending on which constructor is used. Note that
- // this should be done from the IO thread and that the iterator should not be
- // kept around as it may be invalidated on subsequent event processing in the
- // event loop.
- class Iterator {
- public:
- Iterator();
- Iterator(ProcessType type);
- ChildProcessInfo* operator->() { return *iterator_; }
- ChildProcessInfo* operator*() { return *iterator_; }
- ChildProcessInfo* operator++();
- bool Done();
-
- private:
- bool all_;
- ProcessType type_;
- std::list<ChildProcessInfo*>::iterator iterator_;
- };
-
- protected:
- void set_type(ProcessType type) { type_ = type; }
- void set_name(const std::wstring& name) { name_ = name; }
-
- // Derived objects need to use this constructor so we know what type we are.
- ChildProcessInfo(ProcessType type);
-
- private:
- // By making the constructor private, we can ensure that ChildProcessInfo
- // objects can only be created by creating objects derived from them (i.e.
- // PluginProcessHost) or by using the copy constructor or assignment operator
- // to create an object from the former.
- ChildProcessInfo() { }
-
- ProcessType type_;
- std::wstring name_;
-
- // The handle to the process.
- base::Process process_;
-};
-
-#endif // CHROME_COMMON_CHILD_PROCESS_INFO_H_
+// Copyright (c) 2009 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. + +#ifndef CHROME_COMMON_CHILD_PROCESS_INFO_H_ +#define CHROME_COMMON_CHILD_PROCESS_INFO_H_ + +#include <list> +#include <string> + +#include "base/basictypes.h" +#include "base/process.h" + +class ChildProcessInfo; + +// Holds information about a child process. Plugins/workers and other child +// processes that live on the IO thread derive from this. +class ChildProcessInfo { + public: + enum ProcessType { + BROWSER_PROCESS, + RENDER_PROCESS, + PLUGIN_PROCESS, + WORKER_PROCESS, + UNKNOWN_PROCESS, + }; + + // Returns the type of the process. + ProcessType type() const { return type_; } + + // Returns the name of the process. i.e. for plugins it might be Flash, while + // for workers it might be the domain that it's from. + std::wstring name() const { return name_; } + + // Getter to the process. + base::Process& process() { return process_; } + + // Returns an English name of the process type, should only be used for non + // user-visible strings, or debugging pages like about:memory. + static std::wstring GetTypeNameInEnglish(ProcessType type); + + // Returns a localized title for the child process. For example, a plugin + // process would be "Plug-in: Flash" when name is "Flash". + std::wstring GetLocalizedTitle() const; + + ChildProcessInfo(const ChildProcessInfo& original) { + type_ = original.type_; + name_ = original.name_; + process_ = original.process_; + } + + ChildProcessInfo& operator=(const ChildProcessInfo& original) { + if (&original != this) { + type_ = original.type_; + name_ = original.name_; + process_ = original.process_; + } + return *this; + } + + ~ChildProcessInfo(); + + // We define the < operator so that the ChildProcessInfo can be used as a key + // in a std::map. + bool operator <(const ChildProcessInfo& rhs) const { + if (process_.handle() != rhs.process_.handle()) + return process_ .handle() < rhs.process_.handle(); + return name_ < rhs.name_; + } + + bool operator ==(const ChildProcessInfo& rhs) const { + return (process_.handle() == rhs.process_.handle()) && (name_ == rhs.name_); + } + + // The Iterator class allows iteration through either all child processes, or + // ones of a specific type, depending on which constructor is used. Note that + // this should be done from the IO thread and that the iterator should not be + // kept around as it may be invalidated on subsequent event processing in the + // event loop. + class Iterator { + public: + Iterator(); + Iterator(ProcessType type); + ChildProcessInfo* operator->() { return *iterator_; } + ChildProcessInfo* operator*() { return *iterator_; } + ChildProcessInfo* operator++(); + bool Done(); + + private: + bool all_; + ProcessType type_; + std::list<ChildProcessInfo*>::iterator iterator_; + }; + + protected: + void set_type(ProcessType type) { type_ = type; } + void set_name(const std::wstring& name) { name_ = name; } + + // Derived objects need to use this constructor so we know what type we are. + ChildProcessInfo(ProcessType type); + + private: + // By making the constructor private, we can ensure that ChildProcessInfo + // objects can only be created by creating objects derived from them (i.e. + // PluginProcessHost) or by using the copy constructor or assignment operator + // to create an object from the former. + ChildProcessInfo() { } + + ProcessType type_; + std::wstring name_; + + // The handle to the process. + base::Process process_; +}; + +#endif // CHROME_COMMON_CHILD_PROCESS_INFO_H_ diff --git a/chrome/common/extensions/user_script_unittest.cc b/chrome/common/extensions/user_script_unittest.cc index 0266260..72204f4 100644 --- a/chrome/common/extensions/user_script_unittest.cc +++ b/chrome/common/extensions/user_script_unittest.cc @@ -1,101 +1,101 @@ -// Copyright (c) 2009 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 "base/file_path.h"
-#include "base/logging.h"
-#include "chrome/common/extensions/user_script.h"
-#include "googleurl/src/gurl.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-TEST(UserScriptTest, Match1) {
- UserScript script;
- script.add_glob("*mail.google.com*");
- script.add_glob("*mail.yahoo.com*");
- script.add_glob("*mail.msn.com*");
- EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.google.com")));
- EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.google.com/foo")));
- EXPECT_TRUE(script.MatchesUrl(GURL("https://mail.google.com/foo")));
- EXPECT_TRUE(script.MatchesUrl(GURL("ftp://mail.google.com/foo")));
- EXPECT_TRUE(script.MatchesUrl(GURL("http://woo.mail.google.com/foo")));
- EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.yahoo.com/bar")));
- EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.msn.com/baz")));
- EXPECT_FALSE(script.MatchesUrl(GURL("http://www.hotmail.com")));
-}
-
-TEST(UserScriptTest, Match2) {
- UserScript script;
- script.add_glob("*mail.google.com/");
- // GURL normalizes the URL to have a trailing "/"
- EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.google.com")));
- EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.google.com/")));
- EXPECT_FALSE(script.MatchesUrl(GURL("http://mail.google.com/foo")));
-}
-
-TEST(UserScriptTest, Match3) {
- UserScript script;
- script.add_glob("http://mail.google.com/*");
- // GURL normalizes the URL to have a trailing "/"
- EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.google.com")));
- EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.google.com/foo")));
- EXPECT_FALSE(script.MatchesUrl(GURL("https://mail.google.com/foo")));
-}
-
-TEST(UserScriptTest, Match4) {
- UserScript script;
- script.add_glob("*");
- EXPECT_TRUE(script.MatchesUrl(GURL("http://foo.com/bar")));
- EXPECT_TRUE(script.MatchesUrl(GURL("http://hot.com/dog")));
- EXPECT_TRUE(script.MatchesUrl(GURL("https://hot.com/dog")));
- EXPECT_TRUE(script.MatchesUrl(GURL("file:///foo/bar")));
-}
-
-TEST(UserScriptTest, Match5) {
- UserScript script;
- script.add_glob("*foo*");
- EXPECT_TRUE(script.MatchesUrl(GURL("http://foo.com/bar")));
- EXPECT_TRUE(script.MatchesUrl(GURL("http://baz.org/foo/bar")));
- EXPECT_FALSE(script.MatchesUrl(GURL("http://baz.org")));
-}
-
-TEST(UserScriptTest, Match6) {
- URLPattern pattern;
- ASSERT_TRUE(pattern.Parse("http://*/foo*"));
-
- UserScript script;
- script.add_url_pattern(pattern);
- EXPECT_TRUE(script.MatchesUrl(GURL("http://monkey.com/foobar")));
- EXPECT_FALSE(script.MatchesUrl(GURL("http://monkey.com/hotdog")));
-
- // NOTE: URLPattern is tested more extensively in url_pattern_unittest.cc.
-}
-
-TEST(UserScriptTest, Pickle) {
- URLPattern pattern1;
- URLPattern pattern2;
- ASSERT_TRUE(pattern1.Parse("http://*/foo*"));
- ASSERT_TRUE(pattern2.Parse("http://bar/baz*"));
-
- UserScript script1;
- script1.set_url(GURL("chrome-user-script:/foo.user.js"));
- script1.add_url_pattern(pattern1);
- script1.add_url_pattern(pattern2);
-
- Pickle pickle;
- script1.Pickle(&pickle);
-
- void* iter = NULL;
- UserScript script2;
- script2.Unpickle(pickle, &iter);
-
- EXPECT_EQ(script1.url(), script2.url());
- ASSERT_EQ(script1.globs().size(), script2.globs().size());
- for (size_t i = 0; i < script1.globs().size(); ++i) {
- EXPECT_EQ(script1.globs()[i], script2.globs()[i]);
- }
- ASSERT_EQ(script1.url_patterns().size(), script2.url_patterns().size());
- for (size_t i = 0; i < script1.url_patterns().size(); ++i) {
- EXPECT_EQ(script1.url_patterns()[i].GetAsString(),
- script2.url_patterns()[i].GetAsString());
- }
-}
+// Copyright (c) 2009 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 "base/file_path.h" +#include "base/logging.h" +#include "chrome/common/extensions/user_script.h" +#include "googleurl/src/gurl.h" +#include "testing/gtest/include/gtest/gtest.h" + +TEST(UserScriptTest, Match1) { + UserScript script; + script.add_glob("*mail.google.com*"); + script.add_glob("*mail.yahoo.com*"); + script.add_glob("*mail.msn.com*"); + EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.google.com"))); + EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.google.com/foo"))); + EXPECT_TRUE(script.MatchesUrl(GURL("https://mail.google.com/foo"))); + EXPECT_TRUE(script.MatchesUrl(GURL("ftp://mail.google.com/foo"))); + EXPECT_TRUE(script.MatchesUrl(GURL("http://woo.mail.google.com/foo"))); + EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.yahoo.com/bar"))); + EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.msn.com/baz"))); + EXPECT_FALSE(script.MatchesUrl(GURL("http://www.hotmail.com"))); +} + +TEST(UserScriptTest, Match2) { + UserScript script; + script.add_glob("*mail.google.com/"); + // GURL normalizes the URL to have a trailing "/" + EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.google.com"))); + EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.google.com/"))); + EXPECT_FALSE(script.MatchesUrl(GURL("http://mail.google.com/foo"))); +} + +TEST(UserScriptTest, Match3) { + UserScript script; + script.add_glob("http://mail.google.com/*"); + // GURL normalizes the URL to have a trailing "/" + EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.google.com"))); + EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.google.com/foo"))); + EXPECT_FALSE(script.MatchesUrl(GURL("https://mail.google.com/foo"))); +} + +TEST(UserScriptTest, Match4) { + UserScript script; + script.add_glob("*"); + EXPECT_TRUE(script.MatchesUrl(GURL("http://foo.com/bar"))); + EXPECT_TRUE(script.MatchesUrl(GURL("http://hot.com/dog"))); + EXPECT_TRUE(script.MatchesUrl(GURL("https://hot.com/dog"))); + EXPECT_TRUE(script.MatchesUrl(GURL("file:///foo/bar"))); +} + +TEST(UserScriptTest, Match5) { + UserScript script; + script.add_glob("*foo*"); + EXPECT_TRUE(script.MatchesUrl(GURL("http://foo.com/bar"))); + EXPECT_TRUE(script.MatchesUrl(GURL("http://baz.org/foo/bar"))); + EXPECT_FALSE(script.MatchesUrl(GURL("http://baz.org"))); +} + +TEST(UserScriptTest, Match6) { + URLPattern pattern; + ASSERT_TRUE(pattern.Parse("http://*/foo*")); + + UserScript script; + script.add_url_pattern(pattern); + EXPECT_TRUE(script.MatchesUrl(GURL("http://monkey.com/foobar"))); + EXPECT_FALSE(script.MatchesUrl(GURL("http://monkey.com/hotdog"))); + + // NOTE: URLPattern is tested more extensively in url_pattern_unittest.cc. +} + +TEST(UserScriptTest, Pickle) { + URLPattern pattern1; + URLPattern pattern2; + ASSERT_TRUE(pattern1.Parse("http://*/foo*")); + ASSERT_TRUE(pattern2.Parse("http://bar/baz*")); + + UserScript script1; + script1.set_url(GURL("chrome-user-script:/foo.user.js")); + script1.add_url_pattern(pattern1); + script1.add_url_pattern(pattern2); + + Pickle pickle; + script1.Pickle(&pickle); + + void* iter = NULL; + UserScript script2; + script2.Unpickle(pickle, &iter); + + EXPECT_EQ(script1.url(), script2.url()); + ASSERT_EQ(script1.globs().size(), script2.globs().size()); + for (size_t i = 0; i < script1.globs().size(); ++i) { + EXPECT_EQ(script1.globs()[i], script2.globs()[i]); + } + ASSERT_EQ(script1.url_patterns().size(), script2.url_patterns().size()); + for (size_t i = 0; i < script1.url_patterns().size(); ++i) { + EXPECT_EQ(script1.url_patterns()[i].GetAsString(), + script2.url_patterns()[i].GetAsString()); + } +} diff --git a/chrome/common/gfx/DEPS b/chrome/common/gfx/DEPS index 88f24d3..5c5082d 100644 --- a/chrome/common/gfx/DEPS +++ b/chrome/common/gfx/DEPS @@ -1,4 +1,4 @@ -include_rules = [
- "+skia/include",
- "+skia/ext",
+include_rules = [ + "+skia/include", + "+skia/ext", ];
\ No newline at end of file diff --git a/chrome/common/ipc_test_sink.cc b/chrome/common/ipc_test_sink.cc index 7a461b6..c278902 100644 --- a/chrome/common/ipc_test_sink.cc +++ b/chrome/common/ipc_test_sink.cc @@ -1,51 +1,51 @@ -// Copyright (c) 2009 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/common/ipc_test_sink.h"
-
-namespace IPC {
-
-TestSink::TestSink() {
-}
-
-TestSink::~TestSink() {
-}
-
-void TestSink::OnMessageReceived(const Message& msg) {
- messages_.push_back(Message(msg));
-}
-
-void TestSink::ClearMessages() {
- messages_.clear();
-}
-
-const Message* TestSink::GetMessageAt(size_t index) const {
- if (index >= messages_.size())
- return NULL;
- return &messages_[index];
-}
-
-const Message* TestSink::GetFirstMessageMatching(uint16 id) const {
- for (size_t i = 0; i < messages_.size(); i++) {
- if (messages_[i].type() == id)
- return &messages_[i];
- }
- return NULL;
-}
-
-const Message* TestSink::GetUniqueMessageMatching(uint16 id) const {
- size_t found_index = 0;
- size_t found_count = 0;
- for (size_t i = 0; i < messages_.size(); i++) {
- if (messages_[i].type() == id) {
- found_count++;
- found_index = i;
- }
- }
- if (found_count != 1)
- return NULL; // Didn't find a unique one.
- return &messages_[found_index];
-}
-
-} // namespace IPC
+// Copyright (c) 2009 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/common/ipc_test_sink.h" + +namespace IPC { + +TestSink::TestSink() { +} + +TestSink::~TestSink() { +} + +void TestSink::OnMessageReceived(const Message& msg) { + messages_.push_back(Message(msg)); +} + +void TestSink::ClearMessages() { + messages_.clear(); +} + +const Message* TestSink::GetMessageAt(size_t index) const { + if (index >= messages_.size()) + return NULL; + return &messages_[index]; +} + +const Message* TestSink::GetFirstMessageMatching(uint16 id) const { + for (size_t i = 0; i < messages_.size(); i++) { + if (messages_[i].type() == id) + return &messages_[i]; + } + return NULL; +} + +const Message* TestSink::GetUniqueMessageMatching(uint16 id) const { + size_t found_index = 0; + size_t found_count = 0; + for (size_t i = 0; i < messages_.size(); i++) { + if (messages_[i].type() == id) { + found_count++; + found_index = i; + } + } + if (found_count != 1) + return NULL; // Didn't find a unique one. + return &messages_[found_index]; +} + +} // namespace IPC diff --git a/chrome/common/ipc_test_sink.h b/chrome/common/ipc_test_sink.h index 9403deb..fd9faee 100644 --- a/chrome/common/ipc_test_sink.h +++ b/chrome/common/ipc_test_sink.h @@ -1,84 +1,84 @@ -// Copyright (c) 2009 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.
-
-#ifndef CHROME_COMMON_IPC_TEST_SINK_H_
-#define CHROME_COMMON_IPC_TEST_SINK_H_
-
-#include <utility>
-#include <vector>
-
-#include "base/basictypes.h"
-#include "chrome/common/ipc_message.h"
-
-namespace IPC {
-
-// This test sink provides a "sink" for IPC messages that are sent. It allows
-// the caller to query messages received in various different ways. It is
-// designed for tests for objects that use the IPC system.
-//
-// Typical usage:
-//
-// test_sink.ClearMessages();
-// do_something();
-//
-// // We should have gotten exactly one update state message.
-// EXPECT_TRUE(test_sink.GetUniqeMessageMatching(ViewHostMsg_Update::ID));
-// // ...and no start load messages.
-// EXPECT_FALSE(test_sink.GetFirstMessageMatching(ViewHostMsg_Start::ID));
-//
-// // Now inspect a message. This assumes a message that was declared like
-// // this: IPC_MESSAGE_ROUTED2(ViewMsg_Foo, bool, int)
-// IPC::Message* msg = test_sink.GetFirstMessageMatching(ViewMsg_Foo::ID));
-// ASSERT_TRUE(msg);
-// bool first_param;
-// int second_param;
-// ViewMsg_Foo::Read(msg, &first_param, &second_param);
-//
-// // Go on to the next phase of the test.
-// test_sink.ClearMessages();
-//
-// To hook up the sink, all you need to do is call OnMessageReceived when a
-// message is recieved.
-class TestSink {
- public:
- TestSink();
- ~TestSink();
-
- // Used by the source of the messages to send the message to the sink. This
- // will make a copy of the message and store it in the list.
- void OnMessageReceived(const Message& msg);
-
- // Returns the number of messages in the queue.
- size_t message_count() const { return messages_.size(); }
-
- // Clears the message queue of saved messages.
- void ClearMessages();
-
- // Returns the message at the given index in the queue. The index may be out
- // of range, in which case the return value is NULL. The returned pointer will
- // only be valid until another message is received or the list is cleared.
- const Message* GetMessageAt(size_t index) const;
-
- // Returns the first message with the given ID in the queue. If there is no
- // message with the given ID, returns NULL. The returned pointer will only be
- // valid until another message is received or the list is cleared.
- const Message* GetFirstMessageMatching(uint16 id) const;
-
- // Returns the message with the given ID in the queue. If there is no such
- // message or there is more than one of that message, this will return NULL
- // (with the expectation that you'll do an ASSERT_TRUE() on the result).
- // The returned pointer will only be valid until another message is received
- // or the list is cleared.
- const Message* GetUniqueMessageMatching(uint16 id) const;
-
- private:
- // The actual list of received messages.
- std::vector<Message> messages_;
-
- DISALLOW_COPY_AND_ASSIGN(TestSink);
-};
-
-} // namespace IPC
-
-#endif // CHROME_COMMON_IPC_TEST_SINK_H_
+// Copyright (c) 2009 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. + +#ifndef CHROME_COMMON_IPC_TEST_SINK_H_ +#define CHROME_COMMON_IPC_TEST_SINK_H_ + +#include <utility> +#include <vector> + +#include "base/basictypes.h" +#include "chrome/common/ipc_message.h" + +namespace IPC { + +// This test sink provides a "sink" for IPC messages that are sent. It allows +// the caller to query messages received in various different ways. It is +// designed for tests for objects that use the IPC system. +// +// Typical usage: +// +// test_sink.ClearMessages(); +// do_something(); +// +// // We should have gotten exactly one update state message. +// EXPECT_TRUE(test_sink.GetUniqeMessageMatching(ViewHostMsg_Update::ID)); +// // ...and no start load messages. +// EXPECT_FALSE(test_sink.GetFirstMessageMatching(ViewHostMsg_Start::ID)); +// +// // Now inspect a message. This assumes a message that was declared like +// // this: IPC_MESSAGE_ROUTED2(ViewMsg_Foo, bool, int) +// IPC::Message* msg = test_sink.GetFirstMessageMatching(ViewMsg_Foo::ID)); +// ASSERT_TRUE(msg); +// bool first_param; +// int second_param; +// ViewMsg_Foo::Read(msg, &first_param, &second_param); +// +// // Go on to the next phase of the test. +// test_sink.ClearMessages(); +// +// To hook up the sink, all you need to do is call OnMessageReceived when a +// message is recieved. +class TestSink { + public: + TestSink(); + ~TestSink(); + + // Used by the source of the messages to send the message to the sink. This + // will make a copy of the message and store it in the list. + void OnMessageReceived(const Message& msg); + + // Returns the number of messages in the queue. + size_t message_count() const { return messages_.size(); } + + // Clears the message queue of saved messages. + void ClearMessages(); + + // Returns the message at the given index in the queue. The index may be out + // of range, in which case the return value is NULL. The returned pointer will + // only be valid until another message is received or the list is cleared. + const Message* GetMessageAt(size_t index) const; + + // Returns the first message with the given ID in the queue. If there is no + // message with the given ID, returns NULL. The returned pointer will only be + // valid until another message is received or the list is cleared. + const Message* GetFirstMessageMatching(uint16 id) const; + + // Returns the message with the given ID in the queue. If there is no such + // message or there is more than one of that message, this will return NULL + // (with the expectation that you'll do an ASSERT_TRUE() on the result). + // The returned pointer will only be valid until another message is received + // or the list is cleared. + const Message* GetUniqueMessageMatching(uint16 id) const; + + private: + // The actual list of received messages. + std::vector<Message> messages_; + + DISALLOW_COPY_AND_ASSIGN(TestSink); +}; + +} // namespace IPC + +#endif // CHROME_COMMON_IPC_TEST_SINK_H_ diff --git a/chrome/common/notification_observer.h b/chrome/common/notification_observer.h index 4cd6da3..b8c9842 100644 --- a/chrome/common/notification_observer.h +++ b/chrome/common/notification_observer.h @@ -1,23 +1,23 @@ -// Copyright (c) 2009 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.
-
-#ifndef CHROME_COMMON_NOTIFICATION_OBSERVER_H_
-#define CHROME_COMMON_NOTIFICATION_OBSERVER_H_
-
-class NotificationDetails;
-class NotificationSource;
-class NotificationType;
-
-// This is the base class for notification observers. When a matching
-// notification is posted to the notification service, Observe is called.
-class NotificationObserver {
- public:
- virtual ~NotificationObserver();
-
- virtual void Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details) = 0;
-};
-
-#endif // CHROME_COMMON_NOTIFICATION_OBSERVER_H_
+// Copyright (c) 2009 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. + +#ifndef CHROME_COMMON_NOTIFICATION_OBSERVER_H_ +#define CHROME_COMMON_NOTIFICATION_OBSERVER_H_ + +class NotificationDetails; +class NotificationSource; +class NotificationType; + +// This is the base class for notification observers. When a matching +// notification is posted to the notification service, Observe is called. +class NotificationObserver { + public: + virtual ~NotificationObserver(); + + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) = 0; +}; + +#endif // CHROME_COMMON_NOTIFICATION_OBSERVER_H_ |