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

Side by Side Diff: chrome/browser/extensions/api/page_capture/page_capture_apitest.cc

Issue 2552203007: Public Sessions - prompt the user for pageCapture requests (Closed)
Patch Set: Devlin's comments Created 3 years, 11 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
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/base_switches.h" 5 #include "base/base_switches.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "chrome/browser/extensions/api/page_capture/page_capture_api.h" 7 #include "chrome/browser/extensions/api/page_capture/page_capture_api.h"
8 #include "chrome/browser/extensions/extension_apitest.h" 8 #include "chrome/browser/extensions/extension_apitest.h"
9 #include "chrome/common/chrome_switches.h" 9 #include "chrome/common/chrome_switches.h"
10 #include "chromeos/login/login_state.h"
10 #include "content/public/common/content_switches.h" 11 #include "content/public/common/content_switches.h"
11 #include "content/public/test/test_utils.h" 12 #include "content/public/test/test_utils.h"
13 #include "extensions/browser/extension_dialog_auto_confirm.h"
12 #include "net/dns/mock_host_resolver.h" 14 #include "net/dns/mock_host_resolver.h"
13 15
14 using extensions::PageCaptureSaveAsMHTMLFunction; 16 using extensions::PageCaptureSaveAsMHTMLFunction;
17 using extensions::ScopedTestDialogAutoConfirm;
15 18
16 class ExtensionPageCaptureApiTest : public ExtensionApiTest { 19 class ExtensionPageCaptureApiTest : public ExtensionApiTest {
17 public: 20 public:
18 void SetUpCommandLine(base::CommandLine* command_line) override { 21 void SetUpCommandLine(base::CommandLine* command_line) override {
19 ExtensionApiTest::SetUpCommandLine(command_line); 22 ExtensionApiTest::SetUpCommandLine(command_line);
20 command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose-gc"); 23 command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose-gc");
21 } 24 }
22 }; 25 };
23 26
24 class PageCaptureSaveAsMHTMLDelegate 27 class PageCaptureSaveAsMHTMLDelegate
(...skipping 18 matching lines...) Expand all
43 host_resolver()->AddRule("www.a.com", "127.0.0.1"); 46 host_resolver()->AddRule("www.a.com", "127.0.0.1");
44 ASSERT_TRUE(StartEmbeddedTestServer()); 47 ASSERT_TRUE(StartEmbeddedTestServer());
45 PageCaptureSaveAsMHTMLDelegate delegate; 48 PageCaptureSaveAsMHTMLDelegate delegate;
46 ASSERT_TRUE(RunExtensionTest("page_capture")) << message_; 49 ASSERT_TRUE(RunExtensionTest("page_capture")) << message_;
47 ASSERT_FALSE(delegate.temp_file_.empty()); 50 ASSERT_FALSE(delegate.temp_file_.empty());
48 // Flush the message loops to make sure the delete happens. 51 // Flush the message loops to make sure the delete happens.
49 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE); 52 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE);
50 content::RunAllPendingInMessageLoop(content::BrowserThread::IO); 53 content::RunAllPendingInMessageLoop(content::BrowserThread::IO);
51 ASSERT_FALSE(base::PathExists(delegate.temp_file_)); 54 ASSERT_FALSE(base::PathExists(delegate.temp_file_));
52 } 55 }
56
57 #if defined(OS_CHROMEOS)
58 IN_PROC_BROWSER_TEST_F(ExtensionPageCaptureApiTest,
59 PublicSessionRequestAllowed) {
60 host_resolver()->AddRule("www.a.com", "127.0.0.1");
61 ASSERT_TRUE(StartEmbeddedTestServer());
62 PageCaptureSaveAsMHTMLDelegate delegate;
63 // Set Public Session state.
64 chromeos::LoginState::Get()->SetLoggedInState(
65 chromeos::LoginState::LOGGED_IN_ACTIVE,
66 chromeos::LoginState::LOGGED_IN_USER_PUBLIC_ACCOUNT);
67 // Resolve Permission dialog with Allow.
68 ScopedTestDialogAutoConfirm auto_confirm(ScopedTestDialogAutoConfirm::ACCEPT);
69 ASSERT_TRUE(RunExtensionTest("page_capture")) << message_;
70 ASSERT_FALSE(delegate.temp_file_.empty());
Devlin 2017/01/09 18:05:07 Might be worth commenting why expect !empty() here
Ivan Šandrk 2017/01/09 18:33:51 Added comments to the original test.
71 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE);
72 content::RunAllPendingInMessageLoop(content::BrowserThread::IO);
73 ASSERT_FALSE(base::PathExists(delegate.temp_file_));
74 }
75
76 IN_PROC_BROWSER_TEST_F(ExtensionPageCaptureApiTest,
77 PublicSessionRequestDenied) {
78 host_resolver()->AddRule("www.a.com", "127.0.0.1");
79 ASSERT_TRUE(StartEmbeddedTestServer());
80 // Set Public Session state.
81 chromeos::LoginState::Get()->SetLoggedInState(
82 chromeos::LoginState::LOGGED_IN_ACTIVE,
83 chromeos::LoginState::LOGGED_IN_USER_PUBLIC_ACCOUNT);
84 // Resolve Permission dialog with Deny.
85 ScopedTestDialogAutoConfirm auto_confirm(ScopedTestDialogAutoConfirm::CANCEL);
86 ASSERT_TRUE(RunExtensionTestWithArg("page_capture", "REQUEST_DENIED"))
87 << message_;
88 }
89 #endif // defined(OS_CHROMEOS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698