Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / android / tab_model / tab_model_unittest.cc
blob9a195dbf62b4f48e82a8618cd8b248587df6f7ca
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.
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"
14 typedef testing::Test TabModelTest;
16 namespace {
17 class TabModelAndroidProfileMock : public TestingProfile {
18 public:
19 TabModelAndroidProfileMock() {}
20 virtual ~TabModelAndroidProfileMock() {}
22 MOCK_METHOD0(GetOffTheRecordProfile, Profile*());
23 MOCK_METHOD0(HasOffTheRecordProfile, bool());
25 } // namespace
27 class TestTabModel : public TabModel {
28 public:
29 explicit TestTabModel(Profile* profile)
30 : TabModel(profile) {}
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;
37 virtual void CreateTab(content::WebContents* web_contents,
38 int parent_tab_id) OVERRIDE {}
39 virtual content::WebContents* CreateNewTabForDevTools(
40 const GURL& url) OVERRIDE {
41 return NULL;
43 virtual bool IsSessionRestoreInProgress() const OVERRIDE { return false; }
44 virtual void OpenClearBrowsingData() const OVERRIDE {}
45 virtual TabAndroid* GetTabAt(int index) const OVERRIDE {
46 return NULL;
48 virtual void SetActiveIndex(int index) OVERRIDE {}
49 virtual void CloseTabAt(int index) OVERRIDE {}
52 TEST_F(TabModelTest, TestProfileHandling) {
53 // Construct TabModel with standard Profile.
54 TestingProfile testing_profile;
55 TestTabModel tab_model(&testing_profile);
57 // Verify TabModel has the correct profile and profile type.
58 EXPECT_EQ(&testing_profile, tab_model.GetProfile());
59 EXPECT_FALSE(tab_model.IsOffTheRecord());
61 // Notify profile is being destroyed and verify pointer is cleared.
62 content::NotificationService::current()->Notify(
63 chrome::NOTIFICATION_PROFILE_DESTROYED,
64 content::Source<Profile>(&testing_profile),
65 content::NotificationService::NoDetails());
66 EXPECT_EQ(NULL, tab_model.GetProfile());
69 TEST_F(TabModelTest, TestProfileHandlingOffTheRecord) {
70 // Construct TabModel with off-the-record Profile.
71 TabModelAndroidProfileMock testing_profile;
72 EXPECT_CALL(testing_profile, HasOffTheRecordProfile())
73 .WillOnce(testing::Return(true));
74 EXPECT_CALL(testing_profile, GetOffTheRecordProfile())
75 .WillOnce(testing::Return(&testing_profile));
76 TestTabModel tab_model(&testing_profile);
78 // Verify TabModel has the correct profile and profile type.
79 EXPECT_EQ(&testing_profile, tab_model.GetProfile());
80 EXPECT_TRUE(tab_model.IsOffTheRecord());
82 // Notify profile is being destroyed and verify pointer is cleared.
83 content::NotificationService::current()->Notify(
84 chrome::NOTIFICATION_PROFILE_DESTROYED,
85 content::Source<Profile>(&testing_profile),
86 content::NotificationService::NoDetails());
87 EXPECT_EQ(NULL, tab_model.GetProfile());