tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 1 | // Copyright 2014 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. |
| 4 | |
| 5 | #include "chrome/browser/permissions/mock_permission_request.h" |
| 6 | |
| 7 | #include "base/strings/string16.h" |
| 8 | #include "base/strings/utf_string_conversions.h" |
thestig | 4a9b0ef | 2016-08-29 08:22:12 | [diff] [blame] | 9 | #include "chrome/grit/theme_resources.h" |
estade | 20c051a9 | 2016-10-15 22:53:22 | [diff] [blame] | 10 | #include "ui/gfx/vector_icons_public.h" |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 11 | |
| 12 | MockPermissionRequest::MockPermissionRequest() |
| 13 | : MockPermissionRequest("test", |
benwells | 471d1f1 | 2016-07-25 23:58:04 | [diff] [blame] | 14 | "button", |
| 15 | "button", |
| 16 | GURL("http://www.google.com"), |
| 17 | PermissionRequestType::UNKNOWN, |
| 18 | PermissionRequestGestureType::UNKNOWN) {} |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 19 | |
| 20 | MockPermissionRequest::MockPermissionRequest( |
| 21 | const std::string& text) |
| 22 | : MockPermissionRequest(text, |
benwells | 471d1f1 | 2016-07-25 23:58:04 | [diff] [blame] | 23 | "button", |
| 24 | "button", |
| 25 | GURL("http://www.google.com"), |
| 26 | PermissionRequestType::UNKNOWN, |
| 27 | PermissionRequestGestureType::UNKNOWN) {} |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 28 | |
| 29 | MockPermissionRequest::MockPermissionRequest( |
benwells | 471d1f1 | 2016-07-25 23:58:04 | [diff] [blame] | 30 | const std::string& text, |
| 31 | PermissionRequestType request_type, |
| 32 | PermissionRequestGestureType gesture_type) |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 33 | : MockPermissionRequest(text, |
benwells | 471d1f1 | 2016-07-25 23:58:04 | [diff] [blame] | 34 | "button", |
| 35 | "button", |
| 36 | GURL("http://www.google.com"), |
| 37 | request_type, |
| 38 | gesture_type) {} |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 39 | |
| 40 | MockPermissionRequest::MockPermissionRequest( |
| 41 | const std::string& text, |
| 42 | const GURL& url) |
| 43 | : MockPermissionRequest(text, |
benwells | 471d1f1 | 2016-07-25 23:58:04 | [diff] [blame] | 44 | "button", |
| 45 | "button", |
| 46 | url, |
| 47 | PermissionRequestType::UNKNOWN, |
| 48 | PermissionRequestGestureType::UNKNOWN) {} |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 49 | |
| 50 | MockPermissionRequest::MockPermissionRequest( |
| 51 | const std::string& text, |
| 52 | const std::string& accept_label, |
| 53 | const std::string& deny_label) |
| 54 | : MockPermissionRequest(text, |
benwells | 471d1f1 | 2016-07-25 23:58:04 | [diff] [blame] | 55 | accept_label, |
| 56 | deny_label, |
| 57 | GURL("http://www.google.com"), |
| 58 | PermissionRequestType::UNKNOWN, |
| 59 | PermissionRequestGestureType::UNKNOWN) {} |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 60 | |
| 61 | MockPermissionRequest::~MockPermissionRequest() {} |
| 62 | |
estade | 20c051a9 | 2016-10-15 22:53:22 | [diff] [blame] | 63 | PermissionRequest::IconId MockPermissionRequest::GetIconId() const { |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 64 | // Use a valid icon ID to support UI tests. |
estade | 20c051a9 | 2016-10-15 22:53:22 | [diff] [blame] | 65 | return gfx::VectorIconId::WARNING; |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | base::string16 MockPermissionRequest::GetMessageTextFragment() const { |
| 69 | return text_; |
| 70 | } |
| 71 | |
| 72 | GURL MockPermissionRequest::GetOrigin() const { |
| 73 | return origin_; |
| 74 | } |
| 75 | |
| 76 | void MockPermissionRequest::PermissionGranted() { |
| 77 | granted_ = true; |
| 78 | } |
| 79 | |
| 80 | void MockPermissionRequest::PermissionDenied() { |
| 81 | granted_ = false; |
| 82 | } |
| 83 | |
| 84 | void MockPermissionRequest::Cancelled() { |
| 85 | granted_ = false; |
| 86 | cancelled_ = true; |
| 87 | } |
| 88 | |
| 89 | void MockPermissionRequest::RequestFinished() { |
| 90 | finished_ = true; |
| 91 | } |
| 92 | |
| 93 | PermissionRequestType MockPermissionRequest::GetPermissionRequestType() |
| 94 | const { |
| 95 | return request_type_; |
| 96 | } |
| 97 | |
benwells | 471d1f1 | 2016-07-25 23:58:04 | [diff] [blame] | 98 | PermissionRequestGestureType MockPermissionRequest::GetGestureType() |
| 99 | const { |
| 100 | return gesture_type_; |
| 101 | } |
| 102 | |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 103 | bool MockPermissionRequest::granted() { |
| 104 | return granted_; |
| 105 | } |
| 106 | |
| 107 | bool MockPermissionRequest::cancelled() { |
| 108 | return cancelled_; |
| 109 | } |
| 110 | |
| 111 | bool MockPermissionRequest::finished() { |
| 112 | return finished_; |
| 113 | } |
| 114 | |
| 115 | MockPermissionRequest::MockPermissionRequest( |
| 116 | const std::string& text, |
| 117 | const std::string& accept_label, |
| 118 | const std::string& deny_label, |
| 119 | const GURL& origin, |
benwells | 471d1f1 | 2016-07-25 23:58:04 | [diff] [blame] | 120 | PermissionRequestType request_type, |
| 121 | PermissionRequestGestureType gesture_type) |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 122 | : granted_(false), |
| 123 | cancelled_(false), |
| 124 | finished_(false), |
benwells | 471d1f1 | 2016-07-25 23:58:04 | [diff] [blame] | 125 | request_type_(request_type), |
| 126 | gesture_type_(gesture_type) { |
tsergeant | 58defcfb | 2016-07-19 23:47:28 | [diff] [blame] | 127 | text_ = base::UTF8ToUTF16(text); |
| 128 | accept_label_ = base::UTF8ToUTF16(accept_label); |
| 129 | deny_label_ = base::UTF8ToUTF16(deny_label); |
| 130 | origin_ = origin.GetOrigin(); |
| 131 | } |