- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / android / tab_model / tab_model_unittest.cc
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/android/tab_android.h"
6 #include "chrome/browser/chrome_notification_types.h"
7 #include "chrome/browser/ui/android/tab_model/tab_model.h"
8 #include "chrome/test/base/testing_profile.h"
9 #include "content/public/browser/notification_service.h"
10 #include "content/public/browser/notification_source.h"
11 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 typedef testing::Test TabModelTest;
15
16 namespace {
17 class TabModelAndroidProfileMock : public TestingProfile {
18  public:
19   TabModelAndroidProfileMock() {}
20   virtual ~TabModelAndroidProfileMock() {}
21
22   MOCK_METHOD0(GetOffTheRecordProfile, Profile*());
23   MOCK_METHOD0(HasOffTheRecordProfile, bool());
24 };
25 }  // namespace
26
27 class TestTabModel : public TabModel {
28  public:
29   explicit TestTabModel(Profile* profile)
30     : TabModel(profile) {}
31
32   virtual int GetTabCount() const OVERRIDE { return 0; }
33   virtual int GetActiveIndex() const OVERRIDE { return 0; }
34   virtual content::WebContents* GetWebContentsAt(int index) const OVERRIDE {
35     return NULL;
36   }
37   virtual void CreateTab(content::WebContents* web_contents) OVERRIDE {}
38   virtual content::WebContents* CreateTabForTesting(const GURL& url) OVERRIDE {
39     return NULL;
40   }
41   virtual bool IsSessionRestoreInProgress() const OVERRIDE { return false; }
42   virtual void OpenClearBrowsingData() const OVERRIDE {}
43   virtual TabAndroid* GetTabAt(int index) const OVERRIDE {
44     return NULL;
45   }
46   virtual void SetActiveIndex(int index) OVERRIDE {}
47   virtual void CloseTabAt(int index) OVERRIDE {}
48 };
49
50 TEST_F(TabModelTest, TestProfileHandling) {
51   // Construct TabModel with standard Profile.
52   TestingProfile testing_profile;
53   TestTabModel tab_model(&testing_profile);
54
55   // Verify TabModel has the correct profile and profile type.
56   EXPECT_EQ(&testing_profile, tab_model.GetProfile());
57   EXPECT_FALSE(tab_model.IsOffTheRecord());
58
59   // Notify profile is being destroyed and verify pointer is cleared.
60   content::NotificationService::current()->Notify(
61     chrome::NOTIFICATION_PROFILE_DESTROYED,
62     content::Source<Profile>(&testing_profile),
63     content::NotificationService::NoDetails());
64   EXPECT_EQ(NULL, tab_model.GetProfile());
65 }
66
67 TEST_F(TabModelTest, TestProfileHandlingOffTheRecord) {
68   // Construct TabModel with off-the-record Profile.
69   TabModelAndroidProfileMock testing_profile;
70   EXPECT_CALL(testing_profile, HasOffTheRecordProfile())
71     .WillOnce(testing::Return(true));
72   EXPECT_CALL(testing_profile, GetOffTheRecordProfile())
73     .WillOnce(testing::Return(&testing_profile));
74   TestTabModel tab_model(&testing_profile);
75
76   // Verify TabModel has the correct profile and profile type.
77   EXPECT_EQ(&testing_profile, tab_model.GetProfile());
78   EXPECT_TRUE(tab_model.IsOffTheRecord());
79
80   // Notify profile is being destroyed and verify pointer is cleared.
81   content::NotificationService::current()->Notify(
82     chrome::NOTIFICATION_PROFILE_DESTROYED,
83     content::Source<Profile>(&testing_profile),
84     content::NotificationService::NoDetails());
85   EXPECT_EQ(NULL, tab_model.GetProfile());
86 }