OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/chrome_select_file_policy.h" | 5 #include "chrome/browser/ui/chrome_select_file_policy.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/message_loop/message_loop.h" | |
9 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
10 #include "base/values.h" | 9 #include "base/values.h" |
11 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/prefs/browser_prefs.h" | 11 #include "chrome/browser/prefs/browser_prefs.h" |
13 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
15 #include "chrome/test/base/scoped_testing_local_state.h" | 14 #include "chrome/test/base/scoped_testing_local_state.h" |
16 #include "chrome/test/base/testing_browser_process.h" | 15 #include "chrome/test/base/testing_browser_process.h" |
17 #include "components/prefs/pref_service.h" | 16 #include "components/prefs/pref_service.h" |
18 #include "content/public/test/test_browser_thread.h" | 17 #include "content/public/test/test_browser_thread_bundle.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
20 #include "ui/shell_dialogs/select_file_dialog.h" | 19 #include "ui/shell_dialogs/select_file_dialog.h" |
21 | 20 |
22 #if defined(USE_AURA) | 21 #if defined(USE_AURA) |
23 // http://crbug.com/105200 | 22 // http://crbug.com/105200 |
24 #define MAYBE_ExpectAsynchronousListenerCall DISABLED_ExpectAsynchronousListener
Call | 23 #define MAYBE_ExpectAsynchronousListenerCall DISABLED_ExpectAsynchronousListener
Call |
25 #else | 24 #else |
26 #define MAYBE_ExpectAsynchronousListenerCall ExpectAsynchronousListenerCall | 25 #define MAYBE_ExpectAsynchronousListenerCall ExpectAsynchronousListenerCall |
27 #endif | 26 #endif |
28 | 27 |
29 using content::BrowserThread; | |
30 | |
31 namespace { | 28 namespace { |
32 | 29 |
33 class FileSelectionUser : public ui::SelectFileDialog::Listener { | 30 class FileSelectionUser : public ui::SelectFileDialog::Listener { |
34 public: | 31 public: |
35 FileSelectionUser() | 32 FileSelectionUser() |
36 : file_selection_initialisation_in_progress(false) { | 33 : file_selection_initialisation_in_progress(false) { |
37 } | 34 } |
38 | 35 |
39 ~FileSelectionUser() override { | 36 ~FileSelectionUser() override { |
40 if (select_file_dialog_.get()) | 37 if (select_file_dialog_.get()) |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 bool file_selection_initialisation_in_progress; | 78 bool file_selection_initialisation_in_progress; |
82 }; | 79 }; |
83 | 80 |
84 } // namespace | 81 } // namespace |
85 | 82 |
86 typedef testing::Test ChromeSelectFilePolicyTest; | 83 typedef testing::Test ChromeSelectFilePolicyTest; |
87 | 84 |
88 // Tests if SelectFileDialog::SelectFile returns asynchronously with | 85 // Tests if SelectFileDialog::SelectFile returns asynchronously with |
89 // file-selection dialogs disabled by policy. | 86 // file-selection dialogs disabled by policy. |
90 TEST_F(ChromeSelectFilePolicyTest, MAYBE_ExpectAsynchronousListenerCall) { | 87 TEST_F(ChromeSelectFilePolicyTest, MAYBE_ExpectAsynchronousListenerCall) { |
91 base::MessageLoopForUI message_loop; | 88 content::TestBrowserThreadBundle test_browser_thread_bundle; |
92 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | |
93 | 89 |
94 ScopedTestingLocalState local_state( | 90 ScopedTestingLocalState local_state( |
95 TestingBrowserProcess::GetGlobal()); | 91 TestingBrowserProcess::GetGlobal()); |
96 | 92 |
97 std::unique_ptr<FileSelectionUser> file_selection_user( | 93 std::unique_ptr<FileSelectionUser> file_selection_user( |
98 new FileSelectionUser()); | 94 new FileSelectionUser()); |
99 | 95 |
100 // Disallow file-selection dialogs. | 96 // Disallow file-selection dialogs. |
101 local_state.Get()->SetManagedPref(prefs::kAllowFileSelectionDialogs, | 97 local_state.Get()->SetManagedPref(prefs::kAllowFileSelectionDialogs, |
102 base::MakeUnique<base::Value>(false)); | 98 base::MakeUnique<base::Value>(false)); |
103 | 99 |
104 file_selection_user->StartFileSelection(); | 100 file_selection_user->StartFileSelection(); |
105 } | 101 } |
OLD | NEW |