Merge branch 'chrome'

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-03-01 16:24:01 -08:00
2647 changed files with 32546 additions and 325808 deletions

View File

@@ -2,26 +2,26 @@ App = require 'app'
fs = require 'fs'
describe "App", ->
app = null
beforeEach ->
app = new App()
afterEach ->
window.close() for window in app.windows()
waitsFor ->
app.windows().length == 0
window.close() for window in atom.windows
waitsFor "there to be no windows", ->
atom.windows.length == 0
describe "open", ->
describe "when opening a filePath", ->
it "displays it in a new window with the contents of the file loaded", ->
filePath = null
filePath = require.resolve 'fixtures/sample.txt'
expect(app.windows().length).toBe 0
expect(atom.windows.length).toBe 0
app.open filePath
atom.open filePath
expect(app.windows().length).toBe 1
newWindow = app.windows()[0]
expect(newWindow.rootView.editor.buffer.url).toEqual filePath
expect(newWindow.rootView.editor.buffer.getText()).toEqual fs.read(filePath)
waitsFor "window to open", ->
atom.windows.length > 0
runs ->
expect(atom.windows.length).toBe 1
newWindow = atom.windows[0]
expect(newWindow.rootView.editor.buffer.url).toEqual filePath
expect(newWindow.rootView.editor.buffer.getText()).toEqual fs.read(filePath)

View File

@@ -52,13 +52,13 @@ describe "Editor", ->
describe "when soft-wrap is enabled", ->
beforeEach ->
editor.width(9 * 50)
editor.width(11 * 50)
editor.setSoftWrap(true)
editor.attachToDom()
# this verifies the assumption made above in setting the editor's width
# charWidth isn't be calculated until it's the editor is on the DOM, but
# we need to ensure that the maxLineLength is recalculated when we attach.
expect(editor.charWidth).toBe 9
expect(editor.charWidth).toBe 11
it "wraps lines that are too long to fit within the editor's width, adjusting cursor positioning accordingly", ->
expect(editor.lines.find('.line').length).toBe 16
@@ -765,21 +765,21 @@ describe "Editor", ->
describe "cut, copy & paste", ->
beforeEach ->
atom.native.writeToPasteboard('first')
expect(atom.native.readFromPasteboard()).toBe 'first'
$native.writeToPasteboard('first')
expect($native.readFromPasteboard()).toBe 'first'
describe "when a cut event is triggered", ->
it "removes the selected text from the buffer and places it on the pasteboard", ->
editor.getSelection().setBufferRange new Range([0,4], [0,9])
editor.trigger "cut"
expect(editor.buffer.getLine(0)).toBe "var sort = function () {"
expect(atom.native.readFromPasteboard()).toBe 'quick'
expect($native.readFromPasteboard()).toBe 'quick'
describe "when a copy event is triggered", ->
it "copies selected text onto the clipboard", ->
editor.getSelection().setBufferRange new Range([0,4], [0, 13])
editor.trigger "copy"
expect(atom.native.readFromPasteboard()).toBe 'quicksort'
expect($native.readFromPasteboard()).toBe 'quicksort'
describe "when a paste event is triggered", ->
it "pastes text into the buffer", ->

View File

@@ -8,7 +8,7 @@ describe "Project", ->
describe ".getFilePaths()", ->
it "returns a promise which resolves to a list of all file urls in the project, recursively", ->
expectedPaths = (url.replace(project.url, '') for url in fs.list(project.url, true) when fs.isFile url)
expectedPaths = (url.replace(project.url, '') for url in fs.listTree(project.url) when fs.isFile url)
waitsForPromise ->
project.getFilePaths().done (result) ->

View File

@@ -91,7 +91,8 @@ describe "RootView", ->
beforeEach ->
commandHandler = jasmine.createSpy('commandHandler')
rootView.on('foo-command', commandHandler)
atom.globalKeymap.bindKeys('*', 'x': 'foo-command')
window.keymap.bindKeys('*', 'x': 'foo-command')
describe "when a keydown event is triggered on the RootView (not originating from Ace)", ->
it "triggers matching keybindings for that event", ->

View File

@@ -120,44 +120,44 @@ describe "Selection", ->
describe ".cut()", ->
beforeEach ->
atom.native.writeToPasteboard('first')
expect(atom.native.readFromPasteboard()).toBe 'first'
$native.writeToPasteboard('first')
expect($native.readFromPasteboard()).toBe 'first'
it "removes selected text from the buffer and places it on the clipboard", ->
selection.setBufferRange new Range([0,4], [0,13])
selection.cut()
expect(atom.native.readFromPasteboard()).toBe 'quicksort'
expect($native.readFromPasteboard()).toBe 'quicksort'
expect(editor.buffer.getLine(0)).toBe "var = function () {"
expect(selection.isEmpty()).toBeTruthy()
selection.setBufferRange new Range([1,6], [3,8])
selection.cut()
expect(atom.native.readFromPasteboard()).toBe "sort = function(items) {\n if (items.length <= 1) return items;\n var "
expect($native.readFromPasteboard()).toBe "sort = function(items) {\n if (items.length <= 1) return items;\n var "
expect(editor.buffer.getLine(1)).toBe " var pivot = items.shift(), current, left = [], right = [];"
it "places nothing on the clipboard when there is no selection", ->
selection.setBufferRange new Range([0,4], [0,4])
selection.copy()
expect(atom.native.readFromPasteboard()).toBe 'first'
expect($native.readFromPasteboard()).toBe 'first'
describe ".copy()", ->
beforeEach ->
atom.native.writeToPasteboard('first')
expect(atom.native.readFromPasteboard()).toBe 'first'
$native.writeToPasteboard('first')
expect($native.readFromPasteboard()).toBe 'first'
it "places selected text on the clipboard", ->
selection.setBufferRange new Range([0,4], [0,13])
selection.copy()
expect(atom.native.readFromPasteboard()).toBe 'quicksort'
expect($native.readFromPasteboard()).toBe 'quicksort'
selection.setBufferRange new Range([0,4], [3,13])
selection.copy()
expect(atom.native.readFromPasteboard()).toBe "quicksort = function () {\n var sort = function(items) {\n if (items.length <= 1) return items;\n var pivot"
expect($native.readFromPasteboard()).toBe "quicksort = function () {\n var sort = function(items) {\n if (items.length <= 1) return items;\n var pivot"
it "places nothing on the clipboard when there is no selection", ->
selection.setBufferRange new Range([0,4], [0,4])
selection.copy()
expect(atom.native.readFromPasteboard()).toBe 'first'
expect($native.readFromPasteboard()).toBe 'first'
describe ".selectWord()", ->
describe "when the cursor is inside a word", ->

View File

@@ -30,38 +30,3 @@ describe "Window", ->
requireStylesheet('atom.css')
expect($('head style').length).toBe 1
describe "bindMenuItem(path, keyPattern, action)", ->
it "causes the given menu item to be added to the menu when the window is focused and removed when it is blurred", ->
addedPaths = []
spyOn(atom.native, 'addMenuItem').andCallFake (path) -> addedPaths.push(path)
window.bindMenuItem 'Submenu 1 > Item 1'
window.bindMenuItem 'Submenu 1 > Item 2'
window.bindMenuItem 'Submenu 2 > Item 1'
expect(atom.native.addMenuItem).not.toHaveBeenCalled()
$(window).focus()
expect(atom.native.addMenuItem).toHaveBeenCalled()
expect(addedPaths).toContain('Submenu 1 > Item 1')
expect(addedPaths).toContain('Submenu 1 > Item 2')
expect(addedPaths).toContain('Submenu 2 > Item 1')
spyOn(atom.native, 'resetMainMenu')
$(window).blur()
expect(atom.native.resetMainMenu).toHaveBeenCalled()
it "causes the given action to be invoked when the menu item is selected", ->
handler = jasmine.createSpy('menuItemHandler')
window.bindMenuItem 'Submenu > Item', null, handler
$(window).focus()
OSX.NSApp.mainMenu.itemWithTitle('Submenu').submenu.performActionForItemAtIndex(0)
expect(handler).toHaveBeenCalled()

View File

@@ -1,22 +1,19 @@
nakedLoad 'jasmine-jquery'
$ = require 'jquery'
_ = require 'underscore'
Native = require 'native'
GlobalKeymap = require 'global-keymap'
Point = require 'point'
require 'window'
window.showConsole()
beforeEach ->
window.keymap = new GlobalKeymap
window.resetTimeouts()
afterEach ->
(new Native).resetMainMenu()
atom.globalKeymap.reset()
$('#jasmine-content').empty()
window.atom = new (require 'app')
# Use underscore's definition of equality for toEqual assertions
jasmine.Env.prototype.equals_ = _.isEqual
@@ -103,7 +100,7 @@ $.fn.resultOfTrigger = (type) ->
event.result
$.fn.enableKeymap = ->
@on 'keydown', (e) => atom.globalKeymap.handleKeyEvent(e)
@on 'keydown', (e) => window.keymap.handleKeyEvent(e)
$.fn.attachToDom = ->
$('#jasmine-content').append(this)

View File

@@ -1,4 +1,4 @@
fs = require 'fs'
require 'spec-helper'
require path for path in fs.listDirectoryTree(require.resolve '.') when /-spec\.coffee$/.test path
require path for path in fs.listTree(atom.loadPath + "/spec") when /-spec\.coffee$/.test path

View File

@@ -19,19 +19,19 @@ describe "fs", ->
expect(fs.join('a', 'b/c/', 'd/')).toBe 'a/b/c/d/'
describe ".async", ->
describe ".listFiles(directoryPath, recursive)", ->
directoryPath = null
beforeEach -> directoryPath = require.resolve 'fixtures/dir'
directoryPath = null
beforeEach ->
directoryPath = require.resolve 'fixtures/dir'
describe "when recursive is true", ->
it "returns a promise that resolves to the recursive contents of that directory that are files", ->
waitsForPromise ->
fs.async.listFiles(directoryPath, true).done (result) ->
expect(result).toEqual (path for path in fs.list(directoryPath, true) when fs.isFile(path))
describe ".listTree(directoryPath)", ->
it "returns a promise that resolves to the recursive contents of that directory", ->
waitsForPromise ->
fs.async.listTree(directoryPath).done (result) ->
expect(result).toEqual fs.listTree(directoryPath)
describe "when recursive is false", ->
it "returns a promise that resolves to the contents of that directory that are files", ->
waitsForPromise ->
fs.async.listFiles(directoryPath).done (result) ->
expect(result).toEqual (path for path in fs.list(directoryPath) when fs.isFile(path))
describe ".list(directoryPath)", ->
it "returns a promise that resolves to the contents of that directory", ->
waitsForPromise ->
fs.async.list(directoryPath).done (result) ->
expect(result).toEqual fs.list(directoryPath)

View File

@@ -1,64 +0,0 @@
Native = require 'native'
describe "Native", ->
nativeModule = null
beforeEach ->
nativeModule = new Native
describe "addMenuItem(path, keyPattern)", ->
mainMenu = null
mainMenuItems = null
beforeEach ->
mainMenu = OSX.NSApp.mainMenu
mainMenuItems = mainMenu.itemArray
it "adds the item at the path terminus to the main menu, adding submenus as needed", ->
initialMenuCount = mainMenu.itemArray.length
nativeModule.addMenuItem('Submenu 1 > Item 1')
expect(mainMenu.itemArray.length).toBe initialMenuCount + 1
submenu1 = mainMenu.itemWithTitle('Submenu 1').submenu
item1 = submenu1.itemWithTitle('Item 1')
expect(item1).toBeDefined()
nativeModule.addMenuItem('Submenu 1 > Item 2')
expect(mainMenu.itemArray.length).toBe initialMenuCount + 1
expect(submenu1.itemArray.length).toBe 2
item1 = submenu1.itemWithTitle('Item 2')
expect(item1).toBeDefined()
nativeModule.addMenuItem('Submenu 2 > Item 1')
expect(mainMenu.itemArray.length).toBe initialMenuCount + 2
expect(submenu1.itemArray.length).toBe 2
submenu1 = mainMenu.itemWithTitle('Submenu 2').submenu
item1 = submenu1.itemWithTitle('Item 1')
expect(item1).toBeDefined()
xit "adds a key equivalent to menu item when one is given", ->
nativeModule.addMenuItem('Submenu 1 > Item 1', "meta-r")
submenu1 = mainMenu.itemWithTitle('Submenu 1').submenu
item1 = submenu1.itemWithTitle('Item 1')
expect(item1.keyEquivalent.valueOf()).toBe 'r'
expect(item1.keyEquivalentModifierMask.valueOf()).toBe OSX.NSCommandKeyMask
it "does not add a key equivalent to menu item when no pattern is given", ->
nativeModule.addMenuItem('Submenu 2 > Item 2')
submenu2 = mainMenu.itemWithTitle('Submenu 2').submenu
item2 = submenu2.itemWithTitle('Item 2')
expect(item2.keyEquivalent.valueOf()).toBe 0
expect(item2.keyEquivalentModifierMask).toBe 0
it "does not add the same item twice", ->
nativeModule.addMenuItem('Submenu > Item')
expect(mainMenu.itemWithTitle('Submenu').submenu.itemArray.length).toBe(1)
nativeModule.addMenuItem('Submenu > Item')
expect(mainMenu.itemWithTitle('Submenu').submenu.itemArray.length).toBe(1)