| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <map> | 5 #include <map> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "ui/message_center/message_center.h" | 22 #include "ui/message_center/message_center.h" |
| 23 #include "ui/message_center/message_center_types.h" | 23 #include "ui/message_center/message_center_types.h" |
| 24 | 24 |
| 25 class TestAddObserver : public message_center::MessageCenterObserver { | 25 class TestAddObserver : public message_center::MessageCenterObserver { |
| 26 public: | 26 public: |
| 27 explicit TestAddObserver(message_center::MessageCenter* message_center) | 27 explicit TestAddObserver(message_center::MessageCenter* message_center) |
| 28 : message_center_(message_center) { | 28 : message_center_(message_center) { |
| 29 message_center_->AddObserver(this); | 29 message_center_->AddObserver(this); |
| 30 } | 30 } |
| 31 | 31 |
| 32 virtual ~TestAddObserver() { message_center_->RemoveObserver(this); } | 32 ~TestAddObserver() override { message_center_->RemoveObserver(this); } |
| 33 | 33 |
| 34 virtual void OnNotificationAdded(const std::string& id) override { | 34 void OnNotificationAdded(const std::string& id) override { |
| 35 std::string log = logs_[id]; | 35 std::string log = logs_[id]; |
| 36 if (log != "") | 36 if (log != "") |
| 37 log += "_"; | 37 log += "_"; |
| 38 logs_[id] = log + "add-" + id; | 38 logs_[id] = log + "add-" + id; |
| 39 } | 39 } |
| 40 | 40 |
| 41 virtual void OnNotificationUpdated(const std::string& id) override { | 41 void OnNotificationUpdated(const std::string& id) override { |
| 42 std::string log = logs_[id]; | 42 std::string log = logs_[id]; |
| 43 if (log != "") | 43 if (log != "") |
| 44 log += "_"; | 44 log += "_"; |
| 45 logs_[id] = log + "update-" + id; | 45 logs_[id] = log + "update-" + id; |
| 46 } | 46 } |
| 47 | 47 |
| 48 const std::string log(const std::string& id) { return logs_[id]; } | 48 const std::string log(const std::string& id) { return logs_[id]; } |
| 49 void reset_logs() { logs_.clear(); } | 49 void reset_logs() { logs_.clear(); } |
| 50 | 50 |
| 51 private: | 51 private: |
| (...skipping 13 matching lines...) Expand all Loading... |
| 65 message_center::MessageCenter* message_center() { | 65 message_center::MessageCenter* message_center() { |
| 66 return g_browser_process->message_center(); | 66 return g_browser_process->message_center(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 Profile* profile() { return browser()->profile(); } | 69 Profile* profile() { return browser()->profile(); } |
| 70 | 70 |
| 71 class TestDelegate : public NotificationDelegate { | 71 class TestDelegate : public NotificationDelegate { |
| 72 public: | 72 public: |
| 73 explicit TestDelegate(const std::string& id) : id_(id) {} | 73 explicit TestDelegate(const std::string& id) : id_(id) {} |
| 74 | 74 |
| 75 virtual void Display() override { log_ += "Display_"; } | 75 void Display() override { log_ += "Display_"; } |
| 76 virtual void Error() override { log_ += "Error_"; } | 76 void Error() override { log_ += "Error_"; } |
| 77 virtual void Close(bool by_user) override { | 77 void Close(bool by_user) override { |
| 78 log_ += "Close_"; | 78 log_ += "Close_"; |
| 79 log_ += ( by_user ? "by_user_" : "programmatically_"); | 79 log_ += ( by_user ? "by_user_" : "programmatically_"); |
| 80 } | 80 } |
| 81 virtual void Click() override { log_ += "Click_"; } | 81 void Click() override { log_ += "Click_"; } |
| 82 virtual void ButtonClick(int button_index) override { | 82 void ButtonClick(int button_index) override { |
| 83 log_ += "ButtonClick_"; | 83 log_ += "ButtonClick_"; |
| 84 log_ += base::IntToString(button_index) + "_"; | 84 log_ += base::IntToString(button_index) + "_"; |
| 85 } | 85 } |
| 86 virtual std::string id() const override { return id_; } | 86 std::string id() const override { return id_; } |
| 87 | 87 |
| 88 const std::string& log() { return log_; } | 88 const std::string& log() { return log_; } |
| 89 | 89 |
| 90 private: | 90 private: |
| 91 virtual ~TestDelegate() {} | 91 ~TestDelegate() override {} |
| 92 std::string id_; | 92 std::string id_; |
| 93 std::string log_; | 93 std::string log_; |
| 94 | 94 |
| 95 DISALLOW_COPY_AND_ASSIGN(TestDelegate); | 95 DISALLOW_COPY_AND_ASSIGN(TestDelegate); |
| 96 }; | 96 }; |
| 97 | 97 |
| 98 Notification CreateTestNotification(const std::string& delegate_id, | 98 Notification CreateTestNotification(const std::string& delegate_id, |
| 99 TestDelegate** delegate = NULL) { | 99 TestDelegate** delegate = NULL) { |
| 100 TestDelegate* new_delegate = new TestDelegate(delegate_id); | 100 TestDelegate* new_delegate = new TestDelegate(delegate_id); |
| 101 if (delegate) { | 101 if (delegate) { |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 manager()->Update(notification, profile()); | 351 manager()->Update(notification, profile()); |
| 352 | 352 |
| 353 // Expect that the progress notification update is performed. | 353 // Expect that the progress notification update is performed. |
| 354 EXPECT_EQ(base::StringPrintf("update-%s", notification_id.c_str()), | 354 EXPECT_EQ(base::StringPrintf("update-%s", notification_id.c_str()), |
| 355 observer.log(notification_id)); | 355 observer.log(notification_id)); |
| 356 | 356 |
| 357 delegate->Release(); | 357 delegate->Release(); |
| 358 } | 358 } |
| 359 | 359 |
| 360 #endif // !defined(OS_MACOSX) | 360 #endif // !defined(OS_MACOSX) |
| OLD | NEW |