Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 008a64e

Browse files
committed
Uses the TestPreferencesImpl when running tests.
The SpecRunner window and the test windows it opens will use the test preferences systems rather than the real things.
1 parent f675c19 commit 008a64e

5 files changed

Lines changed: 121 additions & 35 deletions

File tree

src/main.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ require.config({
4040
}
4141
});
4242

43+
if (window.location.search.indexOf("testEnvironment") > -1) {
44+
require.config({
45+
paths: {
46+
"preferences/PreferencesImpl": "../test/TestPreferencesImpl"
47+
}
48+
});
49+
}
50+
4351
// hack for r.js optimization, move locale to another config call
4452

4553
// Use custom brackets property until CEF sets the correct navigator.language

src/preferences/PreferencesManager.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ define(function (require, exports, module) {
3434

3535
var OldPreferenceStorage = require("preferences/PreferenceStorage").PreferenceStorage,
3636
AppInit = require("utils/AppInit"),
37-
Async = require("utils/Async"),
3837
Commands = require("command/Commands"),
3938
CommandManager = require("command/CommandManager"),
4039
DeprecationWarning = require("utils/DeprecationWarning"),

test/SpecRunner.js

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@
2828
require.config({
2929
baseUrl: "../src",
3030
paths: {
31-
"test" : "../test",
32-
"perf" : "../test/perf",
33-
"spec" : "../test/spec",
34-
"text" : "thirdparty/text/text",
35-
"i18n" : "thirdparty/i18n/i18n",
36-
"fileSystemImpl" : "filesystem/impls/appshell/AppshellFileSystem"
31+
"test" : "../test",
32+
"perf" : "../test/perf",
33+
"spec" : "../test/spec",
34+
"text" : "thirdparty/text/text",
35+
"i18n" : "thirdparty/i18n/i18n",
36+
"fileSystemImpl" : "filesystem/impls/appshell/AppshellFileSystem",
37+
"preferences/PreferencesImpl" : "../test/TestPreferencesImpl"
3738
}
3839
});
3940

@@ -58,7 +59,6 @@ define(function (require, exports, module) {
5859
NodeDomain = require("utils/NodeDomain"),
5960
BootstrapReporterView = require("test/BootstrapReporterView").BootstrapReporterView,
6061
ColorUtils = require("utils/ColorUtils"),
61-
PreferencesManager = require("preferences/PreferencesManager"),
6262
PreferencesBase = require("preferences/PreferencesBase"),
6363
NativeApp = require("utils/NativeApp");
6464

@@ -147,18 +147,6 @@ define(function (require, exports, module) {
147147
}
148148

149149
function _documentReadyHandler() {
150-
var pm = PreferencesManager._manager,
151-
sm = PreferencesManager.stateManager;
152-
pm.removeScope("user");
153-
pm.addScope("user", new PreferencesBase.MemoryStorage(), {
154-
before: "default"
155-
});
156-
157-
sm.removeScope("user");
158-
sm.addScope("user", new PreferencesBase.MemoryStorage(), {
159-
before: "default"
160-
});
161-
162150
if (brackets.app.showDeveloperTools) {
163151
$("#show-dev-tools").click(function () {
164152
brackets.app.showDeveloperTools();

test/TestPreferencesImpl.js

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* Copyright (c) 2014 Adobe Systems Incorporated. All rights reserved.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20+
* DEALINGS IN THE SOFTWARE.
21+
*
22+
*/
23+
24+
25+
/*global define, $, localStorage, brackets, console */
26+
27+
/**
28+
* Generates the fully configured preferences systems used IN TESTING. This configuration does
29+
* not manipulate the user's preferences.
30+
*/
31+
define(function (require, exports, module) {
32+
"use strict";
33+
34+
var PreferencesBase = require("./PreferencesBase"),
35+
36+
// The SETTINGS_FILENAME is used with a preceding "." within user projects
37+
SETTINGS_FILENAME = "brackets.json",
38+
STATE_FILENAME = "state.json",
39+
40+
// User-level preferences
41+
userPrefFile = null;
42+
43+
/**
44+
* A deferred object which is used to indicate PreferenceManager readiness during the start-up.
45+
* @private
46+
* @type {$.Deferred}
47+
*/
48+
var _prefManagerReadyDeferred = new $.Deferred();
49+
50+
/**
51+
* A boolean property indicating if the user scope configuration file is malformed.
52+
*/
53+
var userScopeCorrupt = false;
54+
55+
function isUserScopeCorrupt() {
56+
return userScopeCorrupt;
57+
}
58+
59+
var manager = new PreferencesBase.PreferencesSystem();
60+
manager.pauseChangeEvents();
61+
62+
// Create a Project scope
63+
var projectStorage = new PreferencesBase.FileStorage(undefined, true),
64+
projectScope = new PreferencesBase.Scope(projectStorage),
65+
projectPathLayer = new PreferencesBase.PathLayer();
66+
67+
projectScope.addLayer(projectPathLayer);
68+
69+
var userScopeLoading = manager.addScope("user", new PreferencesBase.MemoryStorage());
70+
71+
// Set up the .brackets.json file handling
72+
manager.addScope("project", projectScope, {
73+
before: "user"
74+
});
75+
76+
// Session Scope is for storing prefs in memory only but with the highest precedence.
77+
manager.addScope("session", new PreferencesBase.MemoryStorage());
78+
79+
// Memory storages take no time to initialize
80+
_prefManagerReadyDeferred.resolve();
81+
82+
// "State" is stored like preferences but it is not generally intended to be user-editable.
83+
// It's for more internal, implicit things like window size, working set, etc.
84+
var stateManager = new PreferencesBase.PreferencesSystem();
85+
var smUserScope = new PreferencesBase.Scope(new PreferencesBase.MemoryStorage());
86+
var stateProjectLayer = new PreferencesBase.ProjectLayer();
87+
smUserScope.addLayer(stateProjectLayer);
88+
var smUserScopeLoading = stateManager.addScope("user", smUserScope);
89+
90+
// Semi-Public API. Use this at your own risk. The public API is in PreferencesManager.
91+
exports.manager = manager;
92+
exports.projectStorage = projectStorage;
93+
exports.projectPathLayer = projectPathLayer;
94+
exports.userScopeLoading = userScopeLoading;
95+
exports.stateManager = stateManager;
96+
exports.stateProjectLayer = stateProjectLayer;
97+
exports.smUserScopeLoading = smUserScopeLoading;
98+
exports.userPrefFile = userPrefFile;
99+
exports.isUserScopeCorrupt = isUserScopeCorrupt;
100+
exports.managerReady = _prefManagerReadyDeferred.promise();
101+
exports.STATE_FILENAME = STATE_FILENAME;
102+
exports.SETTINGS_FILENAME = SETTINGS_FILENAME;
103+
});

test/spec/SpecRunnerUtils.js

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,9 @@ define(function (require, exports, module) {
494494
// disable initial dialog for live development
495495
params.put("skipLiveDevelopmentInfo", true);
496496

497+
// signals that main.js should configure RequireJS for tests
498+
params.put("testEnvironment", true);
499+
497500
// option to launch test window with either native or HTML menus
498501
if (options && options.hasOwnProperty("hasNativeMenus")) {
499502
params.put("hasNativeMenus", (options.hasNativeMenus ? "true" : "false"));
@@ -542,21 +545,6 @@ define(function (require, exports, module) {
542545
);
543546

544547
runs(function () {
545-
// Reconfigure the preferences manager so that the "user" scoped
546-
// preferences are empty and the tests will not reconfigure
547-
// the preferences of the user running the tests.
548-
var pm = _testWindow.brackets.test.PreferencesManager._manager,
549-
sm = _testWindow.brackets.test.PreferencesManager.stateManager;
550-
pm.removeScope("user");
551-
pm.addScope("user", new PreferencesBase.MemoryStorage(), {
552-
before: "default"
553-
});
554-
555-
sm.removeScope("user");
556-
sm.addScope("user", new PreferencesBase.MemoryStorage(), {
557-
before: "default"
558-
});
559-
560548
// callback allows specs to query the testWindow before they run
561549
callback.call(spec, _testWindow);
562550
});

0 commit comments

Comments
 (0)