15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string>
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h"
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/command_line.h"
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h"
105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/message_loop/message_loop.h"
112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/prefs/pref_service.h"
121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "base/prefs/scoped_user_pref_update.h"
13a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "base/run_loop.h"
14868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/background/background_contents_service.h"
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/background/background_contents_service_factory.h"
177dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "chrome/browser/chrome_notification_types.h"
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/tab_contents/background_contents.h"
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser_list.h"
205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/common/extensions/extension_test_util.h"
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/pref_names.h"
225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/test/base/browser_with_test_window_test.h"
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/test/base/testing_browser_process.h"
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/test/base/testing_profile.h"
255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/test/base/testing_profile_manager.h"
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_service.h"
275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/public/test/test_browser_thread.h"
285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "extensions/common/extension.h"
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h"
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "testing/platform_test.h"
31eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "url/gurl.h"
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#if defined(ENABLE_NOTIFICATIONS)
34a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/browser/notifications/message_center_notification_manager.h"
355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/notifications/notification.h"
36a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/message_center/fake_message_center_tray_delegate.h"
375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/message_center/message_center.h"
385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/message_center/message_center_observer.h"
395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif
405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class BackgroundContentsServiceTest : public testing::Test {
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  BackgroundContentsServiceTest() {}
442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~BackgroundContentsServiceTest() {}
452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void SetUp() {
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    command_line_.reset(new CommandLine(CommandLine::NO_PROGRAM));
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const base::DictionaryValue* GetPrefs(Profile* profile) {
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return profile->GetPrefs()->GetDictionary(
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        prefs::kRegisteredBackgroundContents);
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the stored pref URL for the passed app id.
55a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  std::string GetPrefURLForApp(Profile* profile, const base::string16& appid) {
565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const base::DictionaryValue* pref = GetPrefs(profile);
575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    EXPECT_TRUE(pref->HasKey(base::UTF16ToUTF8(appid)));
585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const base::DictionaryValue* value;
595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    pref->GetDictionaryWithoutPathExpansion(base::UTF16ToUTF8(appid), &value);
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    std::string url;
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    value->GetString("url", &url);
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return url;
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_ptr<CommandLine> command_line_;
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class MockBackgroundContents : public BackgroundContents {
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  explicit MockBackgroundContents(Profile* profile)
715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      : appid_(base::ASCIIToUTF16("app_id")),
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        profile_(profile) {
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MockBackgroundContents(Profile* profile, const std::string& id)
755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      : appid_(base::ASCIIToUTF16(id)),
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        profile_(profile) {
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SendOpenedNotification(BackgroundContentsService* service) {
805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    base::string16 frame_name = base::ASCIIToUTF16("background");
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    BackgroundContentsOpenedDetails details = {
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        this, frame_name, appid_ };
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    service->BackgroundContentsOpened(&details);
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void Navigate(GURL url) {
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    url_ = url;
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    content::NotificationService::current()->Notify(
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED,
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        content::Source<Profile>(profile_),
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        content::Details<BackgroundContents>(this));
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual const GURL& GetURL() const OVERRIDE { return url_; }
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void MockClose(Profile* profile) {
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    content::NotificationService::current()->Notify(
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        chrome::NOTIFICATION_BACKGROUND_CONTENTS_CLOSED,
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        content::Source<Profile>(profile),
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        content::Details<BackgroundContents>(this));
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    delete this;
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~MockBackgroundContents() {
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    content::NotificationService::current()->Notify(
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED,
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        content::Source<Profile>(profile_),
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        content::Details<BackgroundContents>(this));
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
110a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  const base::string16& appid() { return appid_; }
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GURL url_;
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The ID of our parent application
116a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  base::string16 appid_;
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Parent profile
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Profile* profile_;
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
122a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#if defined(ENABLE_NOTIFICATIONS)
1235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Wait for the notification created.
1245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class NotificationWaiter : public message_center::MessageCenterObserver {
1255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public:
1265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  explicit NotificationWaiter(const std::string& target_id)
1275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      : target_id_(target_id) {}
1285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual ~NotificationWaiter() {}
1295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void WaitForNotificationAdded() {
131a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    DCHECK(!run_loop_.running());
1325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    message_center::MessageCenter* message_center =
1335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        message_center::MessageCenter::Get();
1345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    message_center->AddObserver(this);
136a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    run_loop_.Run();
1375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    message_center->RemoveObserver(this);
1385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
1395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) private:
1415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // message_center::MessageCenterObserver overrides:
1425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void OnNotificationAdded(
1435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      const std::string& notification_id) OVERRIDE {
1445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    if (notification_id == target_id_)
145a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      run_loop_.Quit();
1465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
1475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
148cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual void OnNotificationUpdated(
149cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      const std::string& notification_id) OVERRIDE {
150cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    if (notification_id == target_id_)
151cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      run_loop_.Quit();
152cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  }
153cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
1545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  std::string target_id_;
155a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  base::RunLoop run_loop_;
1565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(NotificationWaiter);
1585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)};
1595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class BackgroundContentsServiceNotificationTest
1615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    : public BrowserWithTestWindowTest {
1625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public:
163a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  BackgroundContentsServiceNotificationTest() {}
1645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual ~BackgroundContentsServiceNotificationTest() {}
1655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Overridden from testing::Test
1675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void SetUp() {
1685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    BrowserWithTestWindowTest::SetUp();
1695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // In ChromeOS environment, BrowserWithTestWindowTest initializes
1705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // MessageCenter.
1715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#if !defined(OS_CHROMEOS)
1725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    message_center::MessageCenter::Initialize();
1735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif
1745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    profile_manager_.reset(new TestingProfileManager(
1755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        TestingBrowserProcess::GetGlobal()));
1765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ASSERT_TRUE(profile_manager_->SetUp());
177a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    MessageCenterNotificationManager* manager =
178a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)        static_cast<MessageCenterNotificationManager*>(
179a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)            g_browser_process->notification_ui_manager());
180a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    manager->SetMessageCenterTrayDelegateForTest(
181a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)        new message_center::FakeMessageCenterTrayDelegate(
182a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)            message_center::MessageCenter::Get(), base::Closure()));
1835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
1845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void TearDown() {
1865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    g_browser_process->notification_ui_manager()->CancelAll();
1875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    profile_manager_.reset();
1885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#if !defined(OS_CHROMEOS)
1895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    message_center::MessageCenter::Shutdown();
1905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif
1915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    BrowserWithTestWindowTest::TearDown();
1925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
1935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) protected:
1955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Creates crash notification for the specified extension and returns
1965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // the created one.
1975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const Notification* CreateCrashNotification(
1985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      scoped_refptr<extensions::Extension> extension) {
1995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    std::string notification_id =
2005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        BackgroundContentsService::GetNotificationIdForExtensionForTesting(
2015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            extension->id());
2025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    NotificationWaiter waiter(notification_id);
203a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    BackgroundContentsService::ShowBalloonForTesting(
204a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)        extension.get(), profile());
2055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    waiter.WaitForNotificationAdded();
2065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return g_browser_process->notification_ui_manager()->FindById(
2085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        notification_id);
2095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
2105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) private:
2125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  scoped_ptr<TestingProfileManager> profile_manager_;
2135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(BackgroundContentsServiceNotificationTest);
2155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)};
2165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif  // ENABLE_NOTIFICATIONS
2175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(BackgroundContentsServiceTest, Create) {
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Check for creation and leaks.
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  TestingProfile profile;
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  BackgroundContentsService service(&profile, command_line_.get());
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(BackgroundContentsServiceTest, BackgroundContentsCreateDestroy) {
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  TestingProfile profile;
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  BackgroundContentsService service(&profile, command_line_.get());
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MockBackgroundContents* contents = new MockBackgroundContents(&profile);
2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_FALSE(service.IsTracked(contents));
2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  contents->SendOpenedNotification(&service);
2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(service.IsTracked(contents));
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  delete contents;
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_FALSE(service.IsTracked(contents));
2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(BackgroundContentsServiceTest, BackgroundContentsUrlAdded) {
2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  TestingProfile profile;
2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  BackgroundContentsService service(&profile, command_line_.get());
23890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  BackgroundContentsServiceFactory::GetInstance()->
239a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      RegisterUserPrefsOnBrowserContextForTest(&profile);
2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GURL orig_url;
2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GURL url("http://a/");
2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GURL url2("http://a/");
2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  {
2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    scoped_ptr<MockBackgroundContents> contents(
2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        new MockBackgroundContents(&profile));
2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    EXPECT_EQ(0U, GetPrefs(&profile)->size());
2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    contents->SendOpenedNotification(&service);
2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    contents->Navigate(url);
2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    EXPECT_EQ(1U, GetPrefs(&profile)->size());
2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    EXPECT_EQ(url.spec(), GetPrefURLForApp(&profile, contents->appid()));
2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Navigate the contents to a new url, should not change url.
2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    contents->Navigate(url2);
2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    EXPECT_EQ(1U, GetPrefs(&profile)->size());
2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    EXPECT_EQ(url.spec(), GetPrefURLForApp(&profile, contents->appid()));
2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Contents are deleted, url should persist.
2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(1U, GetPrefs(&profile)->size());
2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(BackgroundContentsServiceTest, BackgroundContentsUrlAddedAndClosed) {
2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  TestingProfile profile;
2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  BackgroundContentsService service(&profile, command_line_.get());
26590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  BackgroundContentsServiceFactory::GetInstance()->
266a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      RegisterUserPrefsOnBrowserContextForTest(&profile);
2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GURL url("http://a/");
2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MockBackgroundContents* contents = new MockBackgroundContents(&profile);
2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(0U, GetPrefs(&profile)->size());
2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  contents->SendOpenedNotification(&service);
2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  contents->Navigate(url);
2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(1U, GetPrefs(&profile)->size());
2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(url.spec(), GetPrefURLForApp(&profile, contents->appid()));
2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Fake a window closed by script.
2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  contents->MockClose(&profile);
2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(0U, GetPrefs(&profile)->size());
2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Test what happens if a BackgroundContents shuts down (say, due to a renderer
2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// crash) then is restarted. Should not persist URL twice.
2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(BackgroundContentsServiceTest, RestartBackgroundContents) {
2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  TestingProfile profile;
2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  BackgroundContentsService service(&profile, command_line_.get());
28690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  BackgroundContentsServiceFactory::GetInstance()->
287a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      RegisterUserPrefsOnBrowserContextForTest(&profile);
2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GURL url("http://a/");
2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  {
2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    scoped_ptr<MockBackgroundContents> contents(new MockBackgroundContents(
2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        &profile, "appid"));
2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    contents->SendOpenedNotification(&service);
2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    contents->Navigate(url);
2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    EXPECT_EQ(1U, GetPrefs(&profile)->size());
2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    EXPECT_EQ(url.spec(), GetPrefURLForApp(&profile, contents->appid()));
2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Contents deleted, url should be persisted.
2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(1U, GetPrefs(&profile)->size());
3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  {
3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Reopen the BackgroundContents to the same URL, we should not register the
3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // URL again.
3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    scoped_ptr<MockBackgroundContents> contents(new MockBackgroundContents(
3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        &profile, "appid"));
3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    contents->SendOpenedNotification(&service);
3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    contents->Navigate(url);
3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    EXPECT_EQ(1U, GetPrefs(&profile)->size());
3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Ensures that BackgroundContentsService properly tracks the association
3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// between a BackgroundContents and its parent extension, including
3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// unregistering the BC when the extension is uninstalled.
3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(BackgroundContentsServiceTest, TestApplicationIDLinkage) {
3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  TestingProfile profile;
3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  BackgroundContentsService service(&profile, command_line_.get());
31890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  BackgroundContentsServiceFactory::GetInstance()->
319a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      RegisterUserPrefsOnBrowserContextForTest(&profile);
3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(NULL,
3225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            service.GetAppBackgroundContents(base::ASCIIToUTF16("appid")));
3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MockBackgroundContents* contents = new MockBackgroundContents(&profile,
3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                                "appid");
3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_ptr<MockBackgroundContents> contents2(
3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      new MockBackgroundContents(&profile, "appid2"));
3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  contents->SendOpenedNotification(&service);
3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(contents, service.GetAppBackgroundContents(contents->appid()));
3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  contents2->SendOpenedNotification(&service);
3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(contents2.get(), service.GetAppBackgroundContents(
3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      contents2->appid()));
3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(0U, GetPrefs(&profile)->size());
3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Navigate the contents, then make sure the one associated with the extension
3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // is unregistered.
3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GURL url("http://a/");
3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GURL url2("http://b/");
3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  contents->Navigate(url);
3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(1U, GetPrefs(&profile)->size());
3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  contents2->Navigate(url2);
3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(2U, GetPrefs(&profile)->size());
3425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  service.ShutdownAssociatedBackgroundContents(base::ASCIIToUTF16("appid"));
3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_FALSE(service.IsTracked(contents));
3445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(NULL,
3455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            service.GetAppBackgroundContents(base::ASCIIToUTF16("appid")));
3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(1U, GetPrefs(&profile)->size());
3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(url2.spec(), GetPrefURLForApp(&profile, contents2->appid()));
3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
350a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#if defined(ENABLE_NOTIFICATIONS)
351a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)TEST_F(BackgroundContentsServiceNotificationTest, TestShowBalloon) {
3525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  scoped_refptr<extensions::Extension> extension =
3535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      extension_test_util::LoadManifest("image_loading_tracker", "app.json");
3545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_TRUE(extension.get());
3555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_TRUE(extension->GetManifestData("icons"));
3565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const Notification* notification = CreateCrashNotification(extension);
3585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_FALSE(notification->icon().IsEmpty());
3595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
3605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Verify if a test notification can show the default extension icon for
3625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// a crash notification for an extension without icon.
363a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)TEST_F(BackgroundContentsServiceNotificationTest, TestShowBalloonNoIcon) {
3645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Extension manifest file with no 'icon' field.
3655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  scoped_refptr<extensions::Extension> extension =
3665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      extension_test_util::LoadManifest("app", "manifest.json");
3675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_TRUE(extension.get());
3685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_FALSE(extension->GetManifestData("icons"));
3695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const Notification* notification = CreateCrashNotification(extension);
3715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_FALSE(notification->icon().IsEmpty());
3725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
373cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
374cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)TEST_F(BackgroundContentsServiceNotificationTest, TestShowTwoBalloons) {
375cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  TestingProfile profile;
376cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  scoped_refptr<extensions::Extension> extension =
377cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      extension_test_util::LoadManifest("app", "manifest.json");
378cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  ASSERT_TRUE(extension.get());
379cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  CreateCrashNotification(extension);
380cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  CreateCrashNotification(extension);
381cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
382cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  message_center::MessageCenter* message_center =
383cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      message_center::MessageCenter::Get();
384cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  message_center::NotificationList::Notifications notifications =
385cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      message_center->GetVisibleNotifications();
386cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  ASSERT_EQ(1u, notifications.size());
387cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}
3885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif
389