| 1 |
// Copyright 2008 The Closure Library Authors. All Rights Reserved. |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS-IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
/** |
| 16 |
* @fileoverview Mock of goog.editor.field. |
| 17 |
* |
| 18 |
* @author [email protected] (Robby Walker) |
| 19 |
*/ |
| 20 |
|
| 21 |
goog.setTestOnly('goog.testing.editor.FieldMock'); |
| 22 |
goog.provide('goog.testing.editor.FieldMock'); |
| 23 |
|
| 24 |
goog.require('goog.dom'); |
| 25 |
goog.require('goog.dom.Range'); |
| 26 |
goog.require('goog.editor.Field'); |
| 27 |
goog.require('goog.testing.LooseMock'); |
| 28 |
goog.require('goog.testing.mockmatchers'); |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
/** |
| 33 |
* Mock of goog.editor.Field. |
| 34 |
* @param {Window=} opt_window Window the field would edit. Defaults to |
| 35 |
* {@code window}. |
| 36 |
* @param {Window=} opt_appWindow "AppWindow" of the field, which can be |
| 37 |
* different from {@code opt_window} when mocking a field that uses an |
| 38 |
* iframe. Defaults to {@code opt_window}. |
| 39 |
* @param {goog.dom.AbstractRange=} opt_range An object (mock or real) to be |
| 40 |
* returned by getRange(). If omitted, a new goog.dom.Range is created |
| 41 |
* from the window every time getRange() is called. |
| 42 |
* @constructor |
| 43 |
* @extends {goog.testing.LooseMock} |
| 44 |
* @suppress {missingProperties} Mocks do not fit in the type system well. |
| 45 |
* @final |
| 46 |
*/ |
| 47 |
goog.testing.editor.FieldMock = function(opt_window, opt_appWindow, opt_range) { |
| 48 |
goog.testing.LooseMock.call(this, goog.editor.Field); |
| 49 |
opt_window = opt_window || window; |
| 50 |
opt_appWindow = opt_appWindow || opt_window; |
| 51 |
|
| 52 |
this.getAppWindow(); |
| 53 |
this.$anyTimes(); |
| 54 |
this.$returns(opt_appWindow); |
| 55 |
|
| 56 |
this.getRange(); |
| 57 |
this.$anyTimes(); |
| 58 |
this.$does(function() { |
| 59 |
return opt_range || goog.dom.Range.createFromWindow(opt_window); |
| 60 |
}); |
| 61 |
|
| 62 |
this.getEditableDomHelper(); |
| 63 |
this.$anyTimes(); |
| 64 |
this.$returns(goog.dom.getDomHelper(opt_window.document)); |
| 65 |
|
| 66 |
this.usesIframe(); |
| 67 |
this.$anyTimes(); |
| 68 |
|
| 69 |
this.getBaseZindex(); |
| 70 |
this.$anyTimes(); |
| 71 |
this.$returns(0); |
| 72 |
|
| 73 |
this.restoreSavedRange(goog.testing.mockmatchers.ignoreArgument); |
| 74 |
this.$anyTimes(); |
| 75 |
this.$does(function(range) { |
| 76 |
if (range) { |
| 77 |
range.restore(); |
| 78 |
} |
| 79 |
this.focus(); |
| 80 |
}); |
| 81 |
|
| 82 |
// These methods cannot be set on the prototype, because the prototype |
| 83 |
// gets stepped on by the mock framework. |
| 84 |
var inModalMode = false; |
| 85 |
|
| 86 |
/** |
| 87 |
* @return {boolean} Whether we're in modal interaction mode. |
| 88 |
*/ |
| 89 |
this.inModalMode = function() { return inModalMode; }; |
| 90 |
|
| 91 |
/** |
| 92 |
* @param {boolean} mode Sets whether we're in modal interaction mode. |
| 93 |
*/ |
| 94 |
this.setModalMode = function(mode) { inModalMode = mode; }; |
| 95 |
|
| 96 |
var uneditable = false; |
| 97 |
|
| 98 |
/** |
| 99 |
* @return {boolean} Whether the field is uneditable. |
| 100 |
*/ |
| 101 |
this.isUneditable = function() { return uneditable; }; |
| 102 |
|
| 103 |
/** |
| 104 |
* @param {boolean} isUneditable Whether the field is uneditable. |
| 105 |
*/ |
| 106 |
this.setUneditable = function(isUneditable) { uneditable = isUneditable; }; |
| 107 |
}; |
| 108 |
goog.inherits(goog.testing.editor.FieldMock, goog.testing.LooseMock); |