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" |
| 6 |
5 #include "base/file_path.h" | 7 #include "base/file_path.h" |
6 #include "base/file_util.h" | 8 #include "base/file_util.h" |
7 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
8 #include "base/string16.h" | 10 #include "base/string16.h" |
9 #include "base/values.h" | 11 #include "base/values.h" |
10 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
11 #include "chrome/browser/prefs/browser_prefs.h" | 13 #include "chrome/browser/prefs/browser_prefs.h" |
12 #include "chrome/browser/prefs/pref_service.h" | 14 #include "chrome/browser/prefs/pref_service.h" |
13 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/browser/ui/select_file_dialog.h" | 16 #include "chrome/browser/ui/select_file_dialog.h" |
15 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
16 #include "chrome/test/base/testing_browser_process.h" | 18 #include "chrome/test/base/testing_browser_process.h" |
17 #include "chrome/test/base/testing_pref_service.h" | 19 #include "chrome/test/base/testing_pref_service.h" |
18 #include "content/public/test/test_browser_thread.h" | 20 #include "content/public/test/test_browser_thread.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
20 | 22 |
21 #if defined(USE_AURA) | 23 #if defined(USE_AURA) |
22 // http://crbug.com/105200 | 24 // http://crbug.com/105200 |
23 #define MAYBE_ExpectAsynchronousListenerCall DISABLED_ExpectAsynchronousListener
Call | 25 #define MAYBE_ExpectAsynchronousListenerCall DISABLED_ExpectAsynchronousListener
Call |
24 #else | 26 #else |
25 #define MAYBE_ExpectAsynchronousListenerCall ExpectAsynchronousListenerCall | 27 #define MAYBE_ExpectAsynchronousListenerCall ExpectAsynchronousListenerCall |
26 #endif | 28 #endif |
27 | 29 |
28 using content::BrowserThread; | 30 using content::BrowserThread; |
29 | 31 |
| 32 namespace { |
| 33 |
30 class FileSelectionUser : public SelectFileDialog::Listener { | 34 class FileSelectionUser : public SelectFileDialog::Listener { |
31 public: | 35 public: |
32 FileSelectionUser() | 36 FileSelectionUser() |
33 : file_selection_initialisation_in_progress(false) { | 37 : file_selection_initialisation_in_progress(false) { |
34 } | 38 } |
35 | 39 |
36 ~FileSelectionUser() { | 40 ~FileSelectionUser() { |
37 if (select_file_dialog_.get()) | 41 if (select_file_dialog_.get()) |
38 select_file_dialog_->ListenerDestroyed(); | 42 select_file_dialog_->ListenerDestroyed(); |
39 } | 43 } |
40 | 44 |
41 void StartFileSelection() { | 45 void StartFileSelection() { |
42 CHECK(!select_file_dialog_.get()); | 46 CHECK(!select_file_dialog_.get()); |
43 select_file_dialog_ = SelectFileDialog::Create(this); | 47 select_file_dialog_ = SelectFileDialog::Create( |
| 48 this, new ChromeSelectFilePolicy(NULL)); |
44 | 49 |
45 const FilePath file_path; | 50 const FilePath file_path; |
46 const string16 title=string16(); | 51 const string16 title=string16(); |
47 | 52 |
48 file_selection_initialisation_in_progress = true; | 53 file_selection_initialisation_in_progress = true; |
49 select_file_dialog_->SelectFile(SelectFileDialog::SELECT_OPEN_FILE, | 54 select_file_dialog_->SelectFile(SelectFileDialog::SELECT_OPEN_FILE, |
50 title, | 55 title, |
51 file_path, | 56 file_path, |
52 NULL, | 57 NULL, |
53 0, | 58 0, |
54 FILE_PATH_LITERAL(""), | 59 FILE_PATH_LITERAL(""), |
55 NULL, | 60 NULL, |
56 NULL, | |
57 NULL); | 61 NULL); |
58 file_selection_initialisation_in_progress = false; | 62 file_selection_initialisation_in_progress = false; |
59 } | 63 } |
60 | 64 |
61 // SelectFileDialog::Listener implementation. | 65 // SelectFileDialog::Listener implementation. |
62 virtual void FileSelected(const FilePath& path, | 66 virtual void FileSelected(const FilePath& path, |
63 int index, void* params){ | 67 int index, void* params){ |
64 ASSERT_FALSE(file_selection_initialisation_in_progress); | 68 ASSERT_FALSE(file_selection_initialisation_in_progress); |
65 } | 69 } |
66 virtual void MultiFilesSelected( | 70 virtual void MultiFilesSelected( |
67 const std::vector<FilePath>& files, | 71 const std::vector<FilePath>& files, |
68 void* params) { | 72 void* params) { |
69 ASSERT_FALSE(file_selection_initialisation_in_progress); | 73 ASSERT_FALSE(file_selection_initialisation_in_progress); |
70 } | 74 } |
71 virtual void FileSelectionCanceled(void* params) { | 75 virtual void FileSelectionCanceled(void* params) { |
72 ASSERT_FALSE(file_selection_initialisation_in_progress); | 76 ASSERT_FALSE(file_selection_initialisation_in_progress); |
73 } | 77 } |
74 | 78 |
75 private: | 79 private: |
76 scoped_refptr<SelectFileDialog> select_file_dialog_; | 80 scoped_refptr<SelectFileDialog> select_file_dialog_; |
77 | 81 |
78 bool file_selection_initialisation_in_progress; | 82 bool file_selection_initialisation_in_progress; |
79 }; | 83 }; |
80 | 84 |
81 typedef testing::Test FileSelectionDialogTest; | 85 } // namespace |
| 86 |
| 87 typedef testing::Test ChromeSelectFilePolicyTest; |
82 | 88 |
83 // Tests if SelectFileDialog::SelectFile returns asynchronously with | 89 // Tests if SelectFileDialog::SelectFile returns asynchronously with |
84 // file-selection dialogs disabled by policy. | 90 // file-selection dialogs disabled by policy. |
85 TEST_F(FileSelectionDialogTest, MAYBE_ExpectAsynchronousListenerCall) { | 91 TEST_F(ChromeSelectFilePolicyTest, MAYBE_ExpectAsynchronousListenerCall) { |
86 MessageLoopForUI message_loop; | 92 MessageLoopForUI message_loop; |
87 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 93 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
88 | 94 |
89 ScopedTestingLocalState local_state( | 95 ScopedTestingLocalState local_state( |
90 static_cast<TestingBrowserProcess*>(g_browser_process)); | 96 static_cast<TestingBrowserProcess*>(g_browser_process)); |
91 | 97 |
92 scoped_ptr<FileSelectionUser> file_selection_user(new FileSelectionUser()); | 98 scoped_ptr<FileSelectionUser> file_selection_user(new FileSelectionUser()); |
93 | 99 |
94 // Disallow file-selection dialogs. | 100 // Disallow file-selection dialogs. |
95 local_state.Get()->SetManagedPref( | 101 local_state.Get()->SetManagedPref( |
96 prefs::kAllowFileSelectionDialogs, | 102 prefs::kAllowFileSelectionDialogs, |
97 Value::CreateBooleanValue(false)); | 103 Value::CreateBooleanValue(false)); |
98 | 104 |
99 file_selection_user->StartFileSelection(); | 105 file_selection_user->StartFileSelection(); |
100 } | 106 } |
OLD | NEW |