summaryrefslogtreecommitdiffstats
path: root/chrome/browser/rlz/chrome_rlz_tracker_delegate_unittest.cc
blob: fd7d6e00a24e0a619a3aeb8ab7497b5391410411 (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
// 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 "chrome/browser/rlz/chrome_rlz_tracker_delegate.h"

#include "base/memory/scoped_ptr.h"
#include "chrome/browser/chrome_notification_types.h"
#include "content/public/browser/navigation_details.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_source.h"
#include "testing/gtest/include/gtest/gtest.h"

using content::NavigationEntry;
using content::LoadCommittedDetails;

class ChromeRLZTrackerDelegateTest : public testing::Test {
 public:
  ChromeRLZTrackerDelegateTest() : delegate_(new ChromeRLZTrackerDelegate) {}
  ~ChromeRLZTrackerDelegateTest() override {}

  void SendNotification(int type,
                        const content::NotificationSource& source,
                        const content::NotificationDetails& details) {
    content::NotificationObserver* observer = delegate_.get();
    observer->Observe(type, source, details);
  }

 private:
  scoped_ptr<ChromeRLZTrackerDelegate> delegate_;
};

TEST_F(ChromeRLZTrackerDelegateTest, ObserveHandlesBadArgs) {
  scoped_ptr<content::LoadCommittedDetails> details(
      new content::LoadCommittedDetails());
  scoped_ptr<content::NavigationEntry> entry(
      content::NavigationEntry::Create());
  details->entry = entry.get();
  details->entry->SetPageID(0);
  details->entry->SetTransitionType(ui::PAGE_TRANSITION_LINK);
  SendNotification(content::NOTIFICATION_NAV_ENTRY_COMMITTED,
                   content::NotificationService::AllSources(),
                   content::Details<NavigationEntry>(nullptr));
  SendNotification(content::NOTIFICATION_NAV_ENTRY_COMMITTED,
                   content::NotificationService::AllSources(),
                   content::Details<LoadCommittedDetails>(details.get()));
}