Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: chrome/browser/chrome_select_file_policy_unittest.cc

Issue 10667026: Start consolidating cross-port file selection code into ui/base/dialogs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "base/bind.h"
5 #include "base/file_path.h" 6 #include "base/file_path.h"
6 #include "base/file_util.h" 7 #include "base/file_util.h"
7 #include "base/message_loop.h" 8 #include "base/message_loop.h"
8 #include "base/string16.h" 9 #include "base/string16.h"
9 #include "base/values.h" 10 #include "base/values.h"
10 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/chrome_select_file_policy.h"
sky 2012/06/26 00:07:18 test include order should match that of .cc includ
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
34 void SetToTrue(bool* var) {
35 *var = true;
36 }
37
30 class FileSelectionUser : public SelectFileDialog::Listener { 38 class FileSelectionUser : public SelectFileDialog::Listener {
31 public: 39 public:
32 FileSelectionUser() 40 FileSelectionUser()
33 : file_selection_initialisation_in_progress(false) { 41 : file_selection_initialisation_in_progress(false) {
34 } 42 }
35 43
36 ~FileSelectionUser() { 44 ~FileSelectionUser() {
37 if (select_file_dialog_.get()) 45 if (select_file_dialog_.get())
38 select_file_dialog_->ListenerDestroyed(); 46 select_file_dialog_->ListenerDestroyed();
39 } 47 }
40 48
41 void StartFileSelection() { 49 void StartFileSelection(bool* blocked) {
42 CHECK(!select_file_dialog_.get()); 50 CHECK(!select_file_dialog_.get());
43 select_file_dialog_ = SelectFileDialog::Create(this); 51 select_file_dialog_ = SelectFileDialog::Create(this);
44 52
45 const FilePath file_path; 53 const FilePath file_path;
46 const string16 title=string16(); 54 const string16 title=string16();
47 55
48 file_selection_initialisation_in_progress = true; 56 file_selection_initialisation_in_progress = true;
49 select_file_dialog_->SelectFile(SelectFileDialog::SELECT_OPEN_FILE, 57 select_file_dialog_->SelectFile(
50 title, 58 SelectFileDialog::SELECT_OPEN_FILE,
51 file_path, 59 title,
52 NULL, 60 file_path,
53 0, 61 NULL,
54 FILE_PATH_LITERAL(""), 62 0,
55 NULL, 63 FILE_PATH_LITERAL(""),
56 NULL, 64 base::Bind(&SetToTrue, base::Unretained(blocked)),
57 NULL); 65 NULL,
66 NULL);
58 file_selection_initialisation_in_progress = false; 67 file_selection_initialisation_in_progress = false;
59 } 68 }
60 69
61 // SelectFileDialog::Listener implementation. 70 // SelectFileDialog::Listener implementation.
62 virtual void FileSelected(const FilePath& path, 71 virtual void FileSelected(const FilePath& path,
63 int index, void* params){ 72 int index, void* params){
64 ASSERT_FALSE(file_selection_initialisation_in_progress); 73 ASSERT_FALSE(file_selection_initialisation_in_progress);
65 } 74 }
66 virtual void MultiFilesSelected( 75 virtual void MultiFilesSelected(
67 const std::vector<FilePath>& files, 76 const std::vector<FilePath>& files,
68 void* params) { 77 void* params) {
69 ASSERT_FALSE(file_selection_initialisation_in_progress); 78 ASSERT_FALSE(file_selection_initialisation_in_progress);
70 } 79 }
71 virtual void FileSelectionCanceled(void* params) { 80 virtual void FileSelectionCanceled(void* params) {
72 ASSERT_FALSE(file_selection_initialisation_in_progress); 81 ASSERT_FALSE(file_selection_initialisation_in_progress);
73 } 82 }
74 83
75 private: 84 private:
76 scoped_refptr<SelectFileDialog> select_file_dialog_; 85 scoped_refptr<SelectFileDialog> select_file_dialog_;
77 86
78 bool file_selection_initialisation_in_progress; 87 bool file_selection_initialisation_in_progress;
79 }; 88 };
80 89
81 typedef testing::Test FileSelectionDialogTest; 90 } // namespace
91
92 typedef testing::Test ChromeSelectFilePolicyTest;
82 93
83 // Tests if SelectFileDialog::SelectFile returns asynchronously with 94 // Tests if SelectFileDialog::SelectFile returns asynchronously with
84 // file-selection dialogs disabled by policy. 95 // file-selection dialogs disabled by policy.
85 TEST_F(FileSelectionDialogTest, MAYBE_ExpectAsynchronousListenerCall) { 96 TEST_F(ChromeSelectFilePolicyTest, MAYBE_ExpectAsynchronousListenerCall) {
86 MessageLoopForUI message_loop; 97 MessageLoopForUI message_loop;
87 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); 98 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
88 99
100 // We should check chrome policy before spawning a dialog.
101 SelectFileDialog::SetFilePolicy(new ChromeSelectFilePolicy);
102
89 ScopedTestingLocalState local_state( 103 ScopedTestingLocalState local_state(
90 static_cast<TestingBrowserProcess*>(g_browser_process)); 104 static_cast<TestingBrowserProcess*>(g_browser_process));
91 105
92 scoped_ptr<FileSelectionUser> file_selection_user(new FileSelectionUser()); 106 scoped_ptr<FileSelectionUser> file_selection_user(new FileSelectionUser);
93 107
94 // Disallow file-selection dialogs. 108 // Disallow file-selection dialogs.
95 local_state.Get()->SetManagedPref( 109 local_state.Get()->SetManagedPref(
96 prefs::kAllowFileSelectionDialogs, 110 prefs::kAllowFileSelectionDialogs,
97 Value::CreateBooleanValue(false)); 111 Value::CreateBooleanValue(false));
98 112
99 file_selection_user->StartFileSelection(); 113 bool blocked = false;
114 file_selection_user->StartFileSelection(&blocked);
115 EXPECT_TRUE(blocked);
100 } 116 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698