Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / notifications / message_center_notifications_browsertest.cc
index 237d62e..cb97e5a 100644 (file)
@@ -9,6 +9,7 @@
 #include "base/message_loop/message_loop.h"
 #include "base/strings/string_number_conversions.h"
 #include "base/strings/string_util.h"
+#include "base/strings/stringprintf.h"
 #include "base/strings/utf_string_conversions.h"
 #include "chrome/browser/browser_process.h"
 #include "chrome/browser/notifications/message_center_notification_manager.h"
@@ -28,16 +29,16 @@ class TestAddObserver : public message_center::MessageCenterObserver {
     message_center_->AddObserver(this);
   }
 
-  virtual ~TestAddObserver() { message_center_->RemoveObserver(this); }
+  ~TestAddObserver() override { message_center_->RemoveObserver(this); }
 
-  virtual void OnNotificationAdded(const std::string& id) OVERRIDE {
+  void OnNotificationAdded(const std::string& id) override {
     std::string log = logs_[id];
     if (log != "")
       log += "_";
     logs_[id] = log + "add-" + id;
   }
 
-  virtual void OnNotificationUpdated(const std::string& id) OVERRIDE {
+  void OnNotificationUpdated(const std::string& id) override {
     std::string log = logs_[id];
     if (log != "")
       log += "_";
@@ -71,45 +72,40 @@ class MessageCenterNotificationsTest : public InProcessBrowserTest {
    public:
     explicit TestDelegate(const std::string& id) : id_(id) {}
 
-    virtual void Display() OVERRIDE { log_ += "Display_"; }
-    virtual void Error() OVERRIDE { log_ += "Error_"; }
-    virtual void Close(bool by_user) OVERRIDE {
+    void Display() override { log_ += "Display_"; }
+    void Close(bool by_user) override {
       log_ += "Close_";
       log_ += ( by_user ? "by_user_" : "programmatically_");
     }
-    virtual void Click() OVERRIDE { log_ += "Click_"; }
-    virtual void ButtonClick(int button_index) OVERRIDE {
+    void Click() override { log_ += "Click_"; }
+    void ButtonClick(int button_index) override {
       log_ += "ButtonClick_";
       log_ += base::IntToString(button_index) + "_";
     }
-    virtual std::string id() const OVERRIDE { return id_; }
-    virtual content::WebContents* GetWebContents() const OVERRIDE {
-      return NULL;
-    }
+    std::string id() const override { return id_; }
 
     const std::string& log() { return log_; }
 
    private:
-    virtual ~TestDelegate() {}
+    ~TestDelegate() override {}
     std::string id_;
     std::string log_;
 
     DISALLOW_COPY_AND_ASSIGN(TestDelegate);
   };
 
-  Notification CreateTestNotification(const std::string& id,
+  Notification CreateTestNotification(const std::string& delegate_id,
                                       TestDelegate** delegate = NULL) {
-    TestDelegate* new_delegate = new TestDelegate(id);
+    TestDelegate* new_delegate = new TestDelegate(delegate_id);
     if (delegate) {
       *delegate = new_delegate;
       new_delegate->AddRef();
     }
 
     return Notification(GURL("chrome-test://testing/"),
-                        GURL(),
                         base::ASCIIToUTF16("title"),
                         base::ASCIIToUTF16("message"),
-                        blink::WebTextDirectionDefault,
+                        gfx::Image(),
                         base::UTF8ToUTF16("chrome-test://testing/"),
                         base::UTF8ToUTF16("REPLACE-ME"),
                         new_delegate);
@@ -164,7 +160,7 @@ IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, BasicAddCancel) {
   manager()->CancelAll();
   manager()->Add(CreateTestNotification("hey"), profile());
   EXPECT_EQ(1u, message_center()->NotificationCount());
-  manager()->CancelById("hey");
+  manager()->CancelById("hey", NotificationUIManager::GetProfileID(profile()));
   EXPECT_EQ(0u, message_center()->NotificationCount());
 }
 
@@ -179,7 +175,7 @@ IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, BasicDelegate) {
   manager()->Add(CreateTestNotification("hey", &delegate), profile());
   // Verify that delegate accumulated correct log of events.
   EXPECT_EQ("Display_", delegate->log());
-  manager()->CancelById("hey");
+  manager()->CancelById("hey", NotificationUIManager::GetProfileID(profile()));
   // Verify that delegate accumulated correct log of events.
   EXPECT_EQ("Display_Close_programmatically_", delegate->log());
   delegate->Release();
@@ -194,7 +190,9 @@ IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, ButtonClickedDelegate) {
 
   TestDelegate* delegate;
   manager()->Add(CreateTestNotification("n", &delegate), profile());
-  message_center()->ClickOnNotificationButton("n", 1);
+  const std::string notification_id =
+      manager()->GetMessageCenterNotificationIdForTest("n", profile());
+  message_center()->ClickOnNotificationButton(notification_id, 1);
   // Verify that delegate accumulated correct log of events.
   EXPECT_EQ("Display_ButtonClick_1_", delegate->log());
   delegate->Release();
@@ -213,7 +211,7 @@ IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest,
   TestDelegate* delegate2;
   manager()->Add(CreateRichTestNotification("n", &delegate2), profile());
 
-  manager()->CancelById("n");
+  manager()->CancelById("n", NotificationUIManager::GetProfileID(profile()));
   EXPECT_EQ("Display_", delegate->log());
   EXPECT_EQ("Close_programmatically_", delegate2->log());
 
@@ -234,16 +232,24 @@ IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, QueueWhenCenterVisible) {
   TestDelegate* delegate2;
 
   manager()->Add(CreateTestNotification("n", &delegate), profile());
+  const std::string id_n =
+      manager()->GetMessageCenterNotificationIdForTest("n", profile());
   message_center()->SetVisibility(message_center::VISIBILITY_MESSAGE_CENTER);
   manager()->Add(CreateTestNotification("n2", &delegate2), profile());
+  const std::string id_n2 =
+      manager()->GetMessageCenterNotificationIdForTest("n2", profile());
 
   // 'update-n' should happen since SetVisibility updates is_read status of n.
   // TODO(mukai): fix event handling to happen update-n just once.
-  EXPECT_EQ("add-n_update-n_update-n", observer.log("n"));
+  EXPECT_EQ(base::StringPrintf("add-%s_update-%s_update-%s",
+                               id_n.c_str(),
+                               id_n.c_str(),
+                               id_n.c_str()),
+            observer.log(id_n));
 
   message_center()->SetVisibility(message_center::VISIBILITY_TRANSIENT);
 
-  EXPECT_EQ("add-n2", observer.log("n2"));
+  EXPECT_EQ(base::StringPrintf("add-%s", id_n2.c_str()), observer.log(id_n2));
 
   delegate->Release();
   delegate2->Release();
@@ -265,17 +271,20 @@ IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest,
   // is visible.
   Notification notification = CreateTestNotification("n", &delegate);
   manager()->Add(notification, profile());
-  message_center()->ClickOnNotification("n");
+  const std::string notification_id =
+      manager()->GetMessageCenterNotificationIdForTest("n", profile());
+  message_center()->ClickOnNotification(notification_id);
   message_center()->SetVisibility(message_center::VISIBILITY_MESSAGE_CENTER);
   observer.reset_logs();
   notification.set_title(base::ASCIIToUTF16("title2"));
   manager()->Update(notification, profile());
 
   // Expect that the notification update is not done.
-  EXPECT_EQ("", observer.log("n"));
+  EXPECT_EQ("", observer.log(notification_id));
 
   message_center()->SetVisibility(message_center::VISIBILITY_TRANSIENT);
-  EXPECT_EQ("update-n", observer.log("n"));
+  EXPECT_EQ(base::StringPrintf("update-%s", notification_id.c_str()),
+            observer.log(notification_id));
 
   delegate->Release();
 }
@@ -297,17 +306,20 @@ IN_PROC_BROWSER_TEST_F(
   // message center is visible.
   Notification notification = CreateTestNotification("n", &delegate);
   manager()->Add(notification, profile());
-  message_center()->ClickOnNotification("n");
+  const std::string notification_id =
+      manager()->GetMessageCenterNotificationIdForTest("n", profile());
+  message_center()->ClickOnNotification(notification_id);
   message_center()->SetVisibility(message_center::VISIBILITY_MESSAGE_CENTER);
   observer.reset_logs();
   notification.set_type(message_center::NOTIFICATION_TYPE_PROGRESS);
   manager()->Update(notification, profile());
 
   // Expect that the notification update is not done.
-  EXPECT_EQ("", observer.log("n"));
+  EXPECT_EQ("", observer.log(notification_id));
 
   message_center()->SetVisibility(message_center::VISIBILITY_TRANSIENT);
-  EXPECT_EQ("update-n", observer.log("n"));
+  EXPECT_EQ(base::StringPrintf("update-%s", notification_id.c_str()),
+            observer.log(notification_id));
 
   delegate->Release();
 }
@@ -329,14 +341,17 @@ IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest,
   Notification notification = CreateTestNotification("n", &delegate);
   notification.set_type(message_center::NOTIFICATION_TYPE_PROGRESS);
   manager()->Add(notification, profile());
-  message_center()->ClickOnNotification("n");
+  const std::string notification_id =
+      manager()->GetMessageCenterNotificationIdForTest("n", profile());
+  message_center()->ClickOnNotification(notification_id);
   message_center()->SetVisibility(message_center::VISIBILITY_MESSAGE_CENTER);
   observer.reset_logs();
   notification.set_progress(50);
   manager()->Update(notification, profile());
 
   // Expect that the progress notification update is performed.
-  EXPECT_EQ("update-n", observer.log("n"));
+  EXPECT_EQ(base::StringPrintf("update-%s", notification_id.c_str()),
+            observer.log(notification_id));
 
   delegate->Release();
 }