Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
awef committed Jul 20, 2013
2 parents 3483917 + c1ce287 commit 6b229e7
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 54 deletions.
52 changes: 16 additions & 36 deletions src/core/Bookmark.ChromeBookmarkEntryList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,46 +354,26 @@ module app.Bookmark {
}
}

private removeChromeBookmark (url: string, callback?: Function): void {
if (url in this.nodeIdStore) {
delete this.nodeIdStore[url];
}

chrome.bookmarks.getChildren(
this.rootNodeId,
(res: BookmarkTreeNode[]) => {
var removeIdList: string[] = [], removedCount = 0;

if (res) {
res.forEach((node) => {
var entry:Entry;

if (node.url && node.title) {
entry = ChromeBookmarkEntryList.URLToEntry(node.url);
private removeChromeBookmark (url:string, callback?:Function):void {
var id:string;

if (entry.url === url) {
removeIdList.push(node.id);
}
}
});
}
url = app.URL.fix(url);

if (removeIdList.length === 0 && callback) {
callback(false);
if (id = this.nodeIdStore[url]) {
delete this.nodeIdStore[url];
chrome.bookmarks.remove(id, function () {
if (callback) {
//TODO 失敗検出
callback(true);
}

removeIdList.forEach((id: string) => {
chrome.bookmarks.remove(id, function () {
//TODO 失敗検出
removedCount++;

if (removedCount === removeIdList.length && callback) {
callback(true);
}
});
});
});
}
else {
app.log("warn", "削除しようとしたブックマークの存在が確認できません。");
if (callback) {
callback(false);
}
);
}
}

add (entry:Entry, createChromeBookmark = true, callback?:Function):bool {
Expand Down
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name" : "read.crx 2",
"version" : "0.77",
"version" : "0.78",
"update_url": "http://idawef.com/crx/crx.xml",
"homepage_url": "http://idawef.com/read.crx-2/",
"description" : "2chブラウザ",
Expand Down
60 changes: 43 additions & 17 deletions src/test/app.Bookmark.ChromeBookmarkEntryList.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -696,25 +696,28 @@ describe "app.Bookmark.ChromeBookmarkEntryList", ->
expect(chrome.bookmarks.remove).not.toHaveBeenCalled()
return

it "与えられたURLに対応するブックマークを全て削除する", ->
it "与えられたURLに対応するブックマークを削除する", ->
spyOn(chrome.bookmarks, "remove").andCallThrough()

targetNodeId0 = null
targetNodeId1 = null
removeCallback = jasmine.createSpy("removeCallback")
onCreated = jasmine.createSpy("onCreated")
targetNodeId = null

cbel = new ChromeBookmarkEntryList(TEST_FOLDER_NODE_ID)
chrome.bookmarks.onCreated.addListener (nodeId, node) ->
if node.url is dummyEntry.board0.url
targetNodeId = nodeId
onCreated()
return

dummyEntry.thread0.url = dummyEntry.thread1.url
res = createBookmark([dummyEntry.thread0, dummyEntry.thread1])
removeCallback = jasmine.createSpy("updateCallback")

cbel = new ChromeBookmarkEntryList(TEST_FOLDER_NODE_ID)
cbel.createChromeBookmark(dummyEntry.board0)

waitsFor ->
res.onCreated.wasCalled
onCreated.wasCalled

runs ->
targetNodeId0 = res.results[0].id
targetNodeId1 = res.results[1].id
cbel.removeChromeBookmark(dummyEntry.thread0.url, removeCallback)
cbel.removeChromeBookmark(dummyEntry.board0.url, removeCallback)
return

waitsFor ->
Expand All @@ -724,13 +727,9 @@ describe "app.Bookmark.ChromeBookmarkEntryList", ->
expect(removeCallback.callCount).toBe(1)
expect(removeCallback).toHaveBeenCalledWith(true)

expect(chrome.bookmarks.remove.callCount).toBe(2)
expect(chrome.bookmarks.remove).toHaveBeenCalledWith(
targetNodeId0
jasmine.any(Function)
)
expect(chrome.bookmarks.remove.callCount).toBe(1)
expect(chrome.bookmarks.remove).toHaveBeenCalledWith(
targetNodeId1
targetNodeId
jasmine.any(Function)
)
return
Expand Down Expand Up @@ -1210,6 +1209,33 @@ describe "app.Bookmark.ChromeBookmarkEntryList", ->
return
return

describe "add直後にremoveを行った場合", ->
it "removeChromeBookmarkに失敗する", ->
removeCallback = jasmine.createSpy("removeCallback")

cbel = new ChromeBookmarkEntryList(TEST_FOLDER_NODE_ID)

spyOn(cbel, "removeChromeBookmark").andCallFake (url, callback) ->
cbel.removeChromeBookmark.originalValue.call(cbel, url, removeCallback)
return

cbel.add(dummyEntry.thread0)

expect(cbel.get(dummyEntry.thread0.url)).toEqual(dummyEntry.thread0)

cbel.remove(dummyEntry.thread0.url)

expect(cbel.get(dummyEntry.thread0.url)).toBeNull()

waitsFor ->
removeCallback.wasCalled

runs ->
expect(removeCallback).toHaveBeenCalledWith(false)
return
return
return

describe "addによるブックマーク作成完了後にremoveを行った場合", ->
it "特に問題なし", ->
createCallback = jasmine.createSpy("createCallback")
Expand Down

0 comments on commit 6b229e7

Please sign in to comment.