NaCl docs: add sanitizers to GSoC ideas
[chromium-blink-merge.git] / chrome / browser / ui / chrome_select_file_policy_unittest.cc
blobca15f4511edd78956e748e603ec14e63cfe30faa
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/ui/chrome_select_file_policy.h"
7 #include "base/files/file_path.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/prefs/pref_service.h"
10 #include "base/strings/string16.h"
11 #include "base/values.h"
12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/prefs/browser_prefs.h"
14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/common/pref_names.h"
16 #include "chrome/test/base/scoped_testing_local_state.h"
17 #include "chrome/test/base/testing_browser_process.h"
18 #include "content/public/test/test_browser_thread.h"
19 #include "testing/gtest/include/gtest/gtest.h"
20 #include "ui/shell_dialogs/select_file_dialog.h"
22 #if defined(USE_AURA)
23 // http://crbug.com/105200
24 #define MAYBE_ExpectAsynchronousListenerCall DISABLED_ExpectAsynchronousListenerCall
25 #else
26 #define MAYBE_ExpectAsynchronousListenerCall ExpectAsynchronousListenerCall
27 #endif
29 using content::BrowserThread;
31 namespace {
33 class FileSelectionUser : public ui::SelectFileDialog::Listener {
34 public:
35 FileSelectionUser()
36 : file_selection_initialisation_in_progress(false) {
39 ~FileSelectionUser() override {
40 if (select_file_dialog_.get())
41 select_file_dialog_->ListenerDestroyed();
44 void StartFileSelection() {
45 CHECK(!select_file_dialog_.get());
46 select_file_dialog_ = ui::SelectFileDialog::Create(
47 this, new ChromeSelectFilePolicy(NULL));
49 const base::FilePath file_path;
50 const base::string16 title = base::string16();
52 file_selection_initialisation_in_progress = true;
53 select_file_dialog_->SelectFile(ui::SelectFileDialog::SELECT_OPEN_FILE,
54 title,
55 file_path,
56 NULL,
58 base::FilePath::StringType(),
59 NULL,
60 NULL);
61 file_selection_initialisation_in_progress = false;
64 // ui::SelectFileDialog::Listener implementation.
65 void FileSelected(const base::FilePath& path,
66 int index,
67 void* params) override {
68 ASSERT_FALSE(file_selection_initialisation_in_progress);
70 void MultiFilesSelected(const std::vector<base::FilePath>& files,
71 void* params) override {
72 ASSERT_FALSE(file_selection_initialisation_in_progress);
74 void FileSelectionCanceled(void* params) override {
75 ASSERT_FALSE(file_selection_initialisation_in_progress);
78 private:
79 scoped_refptr<ui::SelectFileDialog> select_file_dialog_;
81 bool file_selection_initialisation_in_progress;
84 } // namespace
86 typedef testing::Test ChromeSelectFilePolicyTest;
88 // Tests if SelectFileDialog::SelectFile returns asynchronously with
89 // file-selection dialogs disabled by policy.
90 TEST_F(ChromeSelectFilePolicyTest, MAYBE_ExpectAsynchronousListenerCall) {
91 base::MessageLoopForUI message_loop;
92 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
94 ScopedTestingLocalState local_state(
95 TestingBrowserProcess::GetGlobal());
97 scoped_ptr<FileSelectionUser> file_selection_user(new FileSelectionUser());
99 // Disallow file-selection dialogs.
100 local_state.Get()->SetManagedPref(prefs::kAllowFileSelectionDialogs,
101 new base::FundamentalValue(false));
103 file_selection_user->StartFileSelection();