summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/app_notification_test_util.cc
blob: 20aaccdac77649ec75b5889a8ee3cd4610f69551 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (c) 2012 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/strings/string_number_conversions.h"
#include "chrome/browser/extensions/app_notification_manager.h"
#include "chrome/browser/extensions/app_notification_test_util.h"
#include "chrome/common/extensions/extension.h"
#include "testing/gtest/include/gtest/gtest.h"

using base::IntToString;
using extensions::AppNotification;
using extensions::AppNotificationList;

namespace app_notification_test_util {

void ExpectListsEqual(const AppNotificationList& one,
                      const AppNotificationList& two) {
  ASSERT_EQ(one.size(), two.size());
  for (size_t i = 0; i < one.size(); i++) {
    ASSERT_TRUE(one[i]->Equals(*two[i]));
  }
}

void AddNotifications(AppNotificationList* list,
                      const std::string& extension_id,
                      int count,
                      const std::string& prefix) {
  for (int i = 0; i < count; i++) {
    std::string guid = prefix + "_guid_" + IntToString(i);
    std::string title = prefix + "_title_" + IntToString(i);
    std::string body = prefix + "_body_" + IntToString(i);
    AppNotification* item = new AppNotification(
        true, base::Time::Now(), guid, extension_id, title, body);
    if (i % 2 == 0) {
      item->set_link_url(GURL("http://www.example.com/" + prefix));
      item->set_link_text(prefix + "_link_" + IntToString(i));
    }
    list->push_back(linked_ptr<AppNotification>(item));
  }
}

bool AddCopiesFromList(extensions::AppNotificationManager* manager,
                       const AppNotificationList& list) {
  bool result = true;
  for (AppNotificationList::const_iterator i = list.begin();
       i != list.end();
       ++i) {
    result = result && manager->Add((*i)->Copy());
  }
  return result;
}

}  // namespace app_notification_test_util