app_controller_mac_unittest.mm 3.35 KB
Newer Older
1
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 3 4 5 6
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import <Cocoa/Cocoa.h>

7
#include "base/files/file_path.h"
8
#include "base/mac/scoped_nsobject.h"
9
#include "base/run_loop.h"
10
#include "base/strings/utf_string_conversions.h"
11
#include "chrome/app/chrome_command_ids.h"
12
#import "chrome/browser/app_controller_mac.h"
13
#include "chrome/browser/browser_process.h"
14
#include "chrome/browser/profiles/profile_manager.h"
15 16 17
#include "chrome/browser/signin/signin_error_controller_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
18 19
#include "chrome/common/chrome_constants.h"
#include "chrome/common/pref_names.h"
20 21
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
22
#include "chrome/test/base/testing_profile_manager.h"
23 24
#include "components/browser_sync/profile_sync_service.h"
#include "components/browser_sync/profile_sync_service_mock.h"
25 26 27
#include "components/signin/core/browser/fake_auth_status_provider.h"
#include "components/signin/core/browser/signin_error_controller.h"
#include "components/signin/core/browser/signin_manager.h"
28
#include "content/public/test/test_browser_thread_bundle.h"
29
#include "testing/platform_test.h"
30 31
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/l10n/l10n_util_mac.h"
32 33

class AppControllerTest : public PlatformTest {
34
 protected:
35 36 37 38 39 40 41 42 43
  AppControllerTest()
      : profile_manager_(TestingBrowserProcess::GetGlobal()),
        profile_(nullptr) {}

  void SetUp() override {
    PlatformTest::SetUp();
    ASSERT_TRUE(profile_manager_.SetUp());
    profile_ = profile_manager_.CreateTestingProfile("New Profile 1");
  }
44

45
  void TearDown() override {
46
    TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL);
47
    base::RunLoop().RunUntilIdle();
48
    PlatformTest::TearDown();
49 50
  }

51
  content::TestBrowserThreadBundle thread_bundle_;
52 53
  TestingProfileManager profile_manager_;
  TestingProfile* profile_;
54 55 56
};

TEST_F(AppControllerTest, DockMenu) {
57
  base::scoped_nsobject<AppController> ac([[AppController alloc] init]);
58 59 60 61 62 63 64
  NSMenu* menu = [ac applicationDockMenu:NSApp];
  NSMenuItem* item;

  EXPECT_TRUE(menu);
  EXPECT_NE(-1, [menu indexOfItemWithTag:IDC_NEW_WINDOW]);
  EXPECT_NE(-1, [menu indexOfItemWithTag:IDC_NEW_INCOGNITO_WINDOW]);
  for (item in [menu itemArray]) {
65
    EXPECT_EQ(ac.get(), [item target]);
66
    EXPECT_EQ(@selector(commandFromDock:), [item action]);
67 68
  }
}
69 70

TEST_F(AppControllerTest, LastProfile) {
71 72
  // Create a second profile.
  base::FilePath dest_path1 = profile_->GetPath();
73
  base::FilePath dest_path2 =
74 75 76
      profile_manager_.CreateTestingProfile("New Profile 2")->GetPath();
  ASSERT_EQ(2U, profile_manager_.profile_manager()->GetNumberOfProfiles());
  ASSERT_EQ(2U, profile_manager_.profile_manager()->GetLoadedProfiles().size());
77 78 79 80 81 82 83 84

  PrefService* local_state = g_browser_process->local_state();
  local_state->SetString(prefs::kProfileLastUsed,
                         dest_path1.BaseName().MaybeAsASCII());

  base::scoped_nsobject<AppController> ac([[AppController alloc] init]);

  // Delete the active profile.
85
  profile_manager_.profile_manager()->ScheduleProfileForDeletion(
86 87
      dest_path1, ProfileManager::CreateCallback());

88
  base::RunLoop().RunUntilIdle();
89 90 91

  EXPECT_EQ(dest_path2, [ac lastProfile]->GetPath());
}