Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / android / tab_model / tab_model_unittest.cc
blob8f099e0a2b23c6541301c1220229089351074206
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 int GetTabCount() const override { return 0; }
33 int GetActiveIndex() const override { return 0; }
34 content::WebContents* GetWebContentsAt(int index) const override {
35 return NULL;
37 void CreateTab(content::WebContents* web_contents,
38 int parent_tab_id) override {}
39 content::WebContents* CreateNewTabForDevTools(const GURL& url) override {
40 return NULL;
42 bool IsSessionRestoreInProgress() const override { return false; }
43 TabAndroid* GetTabAt(int index) const override { return NULL; }
44 void SetActiveIndex(int index) override {}
45 void CloseTabAt(int index) override {}
48 TEST_F(TabModelTest, TestProfileHandling) {
49 // Construct TabModel with standard Profile.
50 TestingProfile testing_profile;
51 TestTabModel tab_model(&testing_profile);
53 // Verify TabModel has the correct profile and profile type.
54 EXPECT_EQ(&testing_profile, tab_model.GetProfile());
55 EXPECT_FALSE(tab_model.IsOffTheRecord());
57 // Notify profile is being destroyed and verify pointer is cleared.
58 content::NotificationService::current()->Notify(
59 chrome::NOTIFICATION_PROFILE_DESTROYED,
60 content::Source<Profile>(&testing_profile),
61 content::NotificationService::NoDetails());
62 EXPECT_EQ(NULL, tab_model.GetProfile());
65 TEST_F(TabModelTest, TestProfileHandlingOffTheRecord) {
66 // Construct TabModel with off-the-record Profile.
67 TabModelAndroidProfileMock testing_profile;
68 EXPECT_CALL(testing_profile, HasOffTheRecordProfile())
69 .WillOnce(testing::Return(true));
70 EXPECT_CALL(testing_profile, GetOffTheRecordProfile())
71 .WillOnce(testing::Return(&testing_profile));
72 TestTabModel tab_model(&testing_profile);
74 // Verify TabModel has the correct profile and profile type.
75 EXPECT_EQ(&testing_profile, tab_model.GetProfile());
76 EXPECT_TRUE(tab_model.IsOffTheRecord());
78 // Notify profile is being destroyed and verify pointer is cleared.
79 content::NotificationService::current()->Notify(
80 chrome::NOTIFICATION_PROFILE_DESTROYED,
81 content::Source<Profile>(&testing_profile),
82 content::NotificationService::NoDetails());
83 EXPECT_EQ(NULL, tab_model.GetProfile());