| OLD | NEW |
| 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/strings/string_number_conversions.h" | 5 #include "base/strings/string_number_conversions.h" |
| 6 #include "base/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/chrome_notification_types.h" | |
| 10 #include "chrome/browser/extensions/api/notifications/notifications_api.h" | 9 #include "chrome/browser/extensions/api/notifications/notifications_api.h" |
| 11 #include "chrome/browser/extensions/extension_apitest.h" | 10 #include "chrome/browser/extensions/extension_apitest.h" |
| 12 #include "chrome/browser/extensions/extension_function_test_utils.h" | 11 #include "chrome/browser/extensions/extension_function_test_utils.h" |
| 13 #include "chrome/browser/notifications/notification.h" | 12 #include "chrome/browser/notifications/notification.h" |
| 14 #include "chrome/browser/notifications/notification_ui_manager.h" | 13 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 15 #include "content/public/browser/notification_service.h" | 14 #include "content/public/browser/notification_service.h" |
| 16 #include "content/public/test/test_utils.h" | 15 #include "content/public/test/test_utils.h" |
| 17 #include "extensions/browser/api/test/test_api.h" | 16 #include "extensions/browser/api/test/test_api.h" |
| 17 #include "extensions/browser/notification_types.h" |
| 18 #include "extensions/common/features/feature.h" | 18 #include "extensions/common/features/feature.h" |
| 19 #include "ui/message_center/message_center.h" | 19 #include "ui/message_center/message_center.h" |
| 20 #include "ui/message_center/notification_list.h" | 20 #include "ui/message_center/notification_list.h" |
| 21 #include "ui/message_center/notifier_settings.h" | 21 #include "ui/message_center/notifier_settings.h" |
| 22 | 22 |
| 23 using extensions::Extension; | 23 using extensions::Extension; |
| 24 | 24 |
| 25 namespace utils = extension_function_test_utils; | 25 namespace utils = extension_function_test_utils; |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 // A class that waits for a |chrome.test.sendMessage| call, ignores the message, | 29 // A class that waits for a |chrome.test.sendMessage| call, ignores the message, |
| 30 // and writes down the user gesture status of the message. | 30 // and writes down the user gesture status of the message. |
| 31 class UserGestureCatcher : public content::NotificationObserver { | 31 class UserGestureCatcher : public content::NotificationObserver { |
| 32 public: | 32 public: |
| 33 UserGestureCatcher() : waiting_(false) { | 33 UserGestureCatcher() : waiting_(false) { |
| 34 registrar_.Add(this, | 34 registrar_.Add(this, |
| 35 chrome::NOTIFICATION_EXTENSION_TEST_MESSAGE, | 35 extensions::NOTIFICATION_EXTENSION_TEST_MESSAGE, |
| 36 content::NotificationService::AllSources()); | 36 content::NotificationService::AllSources()); |
| 37 } | 37 } |
| 38 | 38 |
| 39 virtual ~UserGestureCatcher() {} | 39 virtual ~UserGestureCatcher() {} |
| 40 | 40 |
| 41 bool GetNextResult() { | 41 bool GetNextResult() { |
| 42 if (results_.empty()) { | 42 if (results_.empty()) { |
| 43 waiting_ = true; | 43 waiting_ = true; |
| 44 content::RunMessageLoop(); | 44 content::RunMessageLoop(); |
| 45 waiting_ = false; | 45 waiting_ = false; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 76 // the extension. | 76 // the extension. |
| 77 bool waiting_; | 77 bool waiting_; |
| 78 }; | 78 }; |
| 79 | 79 |
| 80 class NotificationsApiTest : public ExtensionApiTest { | 80 class NotificationsApiTest : public ExtensionApiTest { |
| 81 public: | 81 public: |
| 82 const extensions::Extension* LoadExtensionAndWait( | 82 const extensions::Extension* LoadExtensionAndWait( |
| 83 const std::string& test_name) { | 83 const std::string& test_name) { |
| 84 base::FilePath extdir = test_data_dir_.AppendASCII(test_name); | 84 base::FilePath extdir = test_data_dir_.AppendASCII(test_name); |
| 85 content::WindowedNotificationObserver page_created( | 85 content::WindowedNotificationObserver page_created( |
| 86 chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY, | 86 extensions::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY, |
| 87 content::NotificationService::AllSources()); | 87 content::NotificationService::AllSources()); |
| 88 const extensions::Extension* extension = LoadExtension(extdir); | 88 const extensions::Extension* extension = LoadExtension(extdir); |
| 89 if (extension) { | 89 if (extension) { |
| 90 page_created.Wait(); | 90 page_created.Wait(); |
| 91 } | 91 } |
| 92 return extension; | 92 return extension; |
| 93 } | 93 } |
| 94 }; | 94 }; |
| 95 | 95 |
| 96 } // namespace | 96 } // namespace |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 notification->ButtonClick(0); | 263 notification->ButtonClick(0); |
| 264 EXPECT_TRUE(catcher.GetNextResult()); | 264 EXPECT_TRUE(catcher.GetNextResult()); |
| 265 notification->Click(); | 265 notification->Click(); |
| 266 EXPECT_TRUE(catcher.GetNextResult()); | 266 EXPECT_TRUE(catcher.GetNextResult()); |
| 267 notification->Close(true); | 267 notification->Close(true); |
| 268 EXPECT_TRUE(catcher.GetNextResult()); | 268 EXPECT_TRUE(catcher.GetNextResult()); |
| 269 notification->Close(false); | 269 notification->Close(false); |
| 270 EXPECT_FALSE(catcher.GetNextResult()); | 270 EXPECT_FALSE(catcher.GetNextResult()); |
| 271 } | 271 } |
| 272 } | 272 } |
| OLD | NEW |